{"id":134,"date":"2013-07-18T08:58:33","date_gmt":"2013-07-17T22:58:33","guid":{"rendered":"https:\/\/www.icemoonprison.com\/blog\/?p=134"},"modified":"2017-02-14T22:46:39","modified_gmt":"2017-02-14T11:46:39","slug":"tracking-adsl-modem-statistics-with-nagios","status":"publish","type":"post","link":"https:\/\/www.icemoonprison.com\/blog\/archives\/134","title":{"rendered":"Tracking ADSL modem statistics with Nagios"},"content":{"rendered":"<p>Here at Ice Moon Prison, we are blessed with an ADSL2+ lifeline to the Internet.\u00a0 At the same time, we are cursed with degrading copper and have seen a gradual decline in our sync speeds over the last two years. To monitor the situation, and to provide ammunition to use when technicians doubt our sincerity, we have created <a title=\"Nagios home page\" href=\"https:\/\/www.icemoonprison.com\/blog\/?p=24\">Nagios<\/a> scripts to collect statistics continuously.<\/p>\n<p><!--more--><\/p>\n<p>Ice Moon Prison&#8217;s ADSL modem is a <a title=\"Netcomm product page\" href=\"http:\/\/www.netcommwireless.com\/product\/xdsl\/nb6-rev2\">Netcomm NB6 rev2<\/a>.\u00a0 Before that we used a TP-Link TD-8810 with almost exactly the same configuration. These modems have a\u00a0<a title=\"Telnet on Wikipedia\" href=\"https:\/\/en.wikipedia.org\/wiki\/Telnet\">Telnet<\/a> interface through which you can get line statistics:<\/p>\n<pre>$ telnet 192.168.1.1\r\nTrying 192.168.1.1...\r\nConnected to 192.168.1.1.\r\nEscape character is '^]'.\r\nNetComm ADSL2+ Router NB6_REV2_16M \r\nSoftware Version: 3.65m\r\nLogin name: admin\r\nPassword: \r\n&gt; adsl info --show \r\nadsl: ADSL driver and PHY status\r\nStatus: ShowtimeRetrain Reason: 8000\r\n\u00a0 Channel: FAST, Upstream rate = 386 Kbps, Downstream rate = 1878 Kbps\r\nLink Power State: L0\r\nMode:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ADSL2\r\nChannel:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Fast\r\nTrellis:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 U:ON \/D:ON\r\nLine Status:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 No Defect\r\nTraining Status:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Showtime\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Down\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Up\r\nSNR (dB):\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 13.1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 12.0\r\nAttn(dB):\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 33.0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 27.9\r\nPwr(dBm):\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 17.3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 12.6\r\nMax(Kbps):\u00a0\u00a0\u00a0\u00a0\u00a0 2548\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 430\r\nRate (Kbps):\u00a0\u00a0\u00a0 1878\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 386\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 G.dmt framing\r\nK:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 59(0)\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 12\r\nR:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\r\nS:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\r\nD:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ADSL2 framing\r\nMSGc:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 59\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 11\r\nB:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 58\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 11\r\nM:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\r\nT:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 4\r\nR:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\r\nS:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 3.9529\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 15.5514\r\nL:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 510\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 107\r\nD:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Counters\r\nSF:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 11813593\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 11857063\r\nSFErr:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 109\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 116\r\nRS:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 191970900\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1511603\r\nRSCorr:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 25122\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 112\r\nRSUnCorr:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 535\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\r\n\r\nHEC:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 86\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 23047018\r\nOCD:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\r\nLCD:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\r\nTotal Cells:\u00a0\u00a0\u00a0 840323492\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1467251070\r\nData Cells:\u00a0\u00a0\u00a0\u00a0 38927716\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1652798551\r\nDrop Cells:\u00a0\u00a0\u00a0\u00a0 0\r\nBit Errors:\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2211174114\r\n\r\nES:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 852\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 17027110\r\nSES:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 79\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8274\r\nUAS:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1825\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 520066\r\nAS:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 189713\r\n\r\nINP:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 2.00\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1.19\r\nPER:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16.05\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 16.52\r\ndelay:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 15.81\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 7.77\r\nOR:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 32.38\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 8.23\r\n\r\nBitswap:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 1062\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 81<\/pre>\n<p>We have no idea what most of that means, but among the numbers is the downstream bitrate.\u00a0 Today is not a good day, with a downstream rate of only 1878 kbps.<\/p>\n<p>Having to telnet into the modem to get these numbers is tedious, so we instead wrote a Perl script to do the telnetting for us.\u00a0 This script uses Perl&#8217;s <a title=\"Expect.pm documentation\" href=\"http:\/\/search.cpan.org\/~rgiersig\/Expect-1.21\/Expect.pod\">Expect library<\/a> to initiate a Telnet session and &#8220;type&#8221; commands into it.\u00a0 The script runs forever (or until you send it a <strong>SIGINT<\/strong>), keeping the Telnet session open.\u00a0 To make it run the <tt>adsl info --show<\/tt> command, send the process a <strong>SIGUSR1<\/strong> signal.<\/p>\n<pre>$ cat \/opt\/local\/libexec\/nagios\/adsl-stats.pl\r\n#!\/usr\/bin\/perl -w\r\n\r\nEND {\r\n\u00a0 unlink '\/opt\/local\/var\/nagios\/adsl-stats.pid';\r\n}\r\n\r\nuse Expect;\r\n\r\n$e = Expect-&gt;new();\r\n\r\n$e-&gt;debug(0);\r\n$e-&gt;log_stdout(0);\r\n\r\n# Start Telnet session.\r\n$e-&gt;spawn(\"telnet 192.168.1.1\");\r\n\r\n# Log in.\r\n$e-&gt;expect(\r\n\u00a0 5,\r\n\u00a0 [ 'ogin',\r\n\u00a0\u00a0\u00a0 sub {$self = shift; $self-&gt;send(\"admin\\n\"); exp_continue;} ],\r\n\u00a0 [ 'Password:',\r\n\u00a0\u00a0\u00a0 sub {$self = shift; $self-&gt;send(\"P@ssw0rd\\n\"); exp_continue;} ],\r\n\u00a0 '&gt; '\r\n);\r\n\r\n$logout = 0;\r\n$SIG{INT} = sub { $logout = 1; };\r\n@command = ();\r\n$SIG{USR1} = sub { push @command, 'show'; };\r\n$SIG{USR2} = sub { push @command, 'SNR'; };  # To do.\r\n\r\n# Repeat until told to exit.\r\nwhile (!$logout)\r\n{\r\n\u00a0 if (!@command)\r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 sleep 1; next;\r\n\u00a0 }\r\n\u00a0 $command = shift @command;\r\n\u00a0 if ($command eq 'show')\r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 # Basic ADSL info.\r\n\u00a0\u00a0\u00a0 $e-&gt;send(\"adsl info --show\\n\");\r\n\u00a0\u00a0\u00a0 $e-&gt;expect(5, \"&gt; \");\r\n\u00a0\u00a0\u00a0 my $result = $e-&gt;before();\r\n\u00a0\u00a0\u00a0 if ($result)\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 adslinfoshow($result);\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 else\r\n\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 last;\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0 }\r\n}\r\n\r\n$e-&gt;send(\"logout\\n\");\r\n\r\nsub adslinfoshow\r\n{\r\n\u00a0 my $status = \"\";\r\n\u00a0 my $performance = \"\";\r\n\u00a0 my $returncode = 3;\r\n\u00a0 foreach (split(\/\\n\/, $_[0]))\r\n\u00a0 {\r\n\u00a0\u00a0\u00a0 s\/\\r$\/\/;\r\n\u00a0\u00a0\u00a0 \/^Status: (G\\.994 Training)\/i and do { $status .= \"$1 \"; $returncode = 1; next; };\r\n\u00a0\u00a0\u00a0 \/^Status: (G\\.992 Started)\/i and do { $status .= \"$1 \"; $returncode = 1; next; };\r\n\u00a0\u00a0\u00a0 \/^Status: (G\\.992 Channel Analysis)\/i and do { $status .= \"$1 \"; $returncode = 1; next; };\r\n\u00a0\u00a0\u00a0 \/^Status: (G\\.992 Message Exchange)\/i and do { $status .= \"$1 \"; $returncode = 1; next; };\r\n\u00a0\u00a0\u00a0 \/^Status: (Idle)\/i and do { $status .= \"$1 \"; $returncode = 2; next; };\r\n\u00a0\u00a0\u00a0 \/^Mode:\\s+(.*)$\/i and do { $status .= \"$1 \"; next; };\r\n\u00a0\u00a0\u00a0 \/^Channel:\\s+(.*)$\/i and do { $status .= \"$1 \"; next; };\r\n\u00a0\u00a0\u00a0 \/^Line Status:\\s+(.*)$\/i and\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 do { $status .= \"$1 \"; next; };\r\n\u00a0\u00a0\u00a0 \/^Training Status:\\s+(.*)$\/i and\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 do { $status .= \"$1 \";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $1 eq \"Showtime\" and $returncode = 0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 next; };\r\n\u00a0\u00a0\u00a0 \/^SNR\\s?\\(dB\\):\\s+(.+?)\\s+(.+?)$\/ and\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 do { $performance .= \"'snr-down'=$1dB 'snr-up'=$2dB \"; next; };\r\n\u00a0\u00a0\u00a0 \/^Attn\\s?\\(dB\\):\\s+(.+?)\\s+(.+?)$\/ and\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 do { $performance .= \"'atten-down'=$1dB 'atten-up'=$2dB \"; next; };\r\n\u00a0\u00a0\u00a0 \/^Pwr\\s?\\(dBm\\):\\s+(.+?)\\s+(.+?)$\/ and\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 do { $performance .= \"'power-down'=$1dB 'power-up'=$2dB \"; next; };\r\n\u00a0\u00a0\u00a0 \/^Max\\s?\\(Kbps\\):\\s+(.+?)\\s+(.+?)$\/ and\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 do { $performance .= \"'maxrate-down'=$1kbps 'maxrate-up'=$2kbps \"; next; };\r\n\u00a0\u00a0\u00a0 \/^Rate\\s?\\(Kbps\\):\\s+(.+?)\\s+(.+?)$\/ and\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 do { $status .= \"$1\/$2kbps \";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 $performance .= \"'rate-down'=$1kbps 'rate-up'=$2kbps \"; next; };\r\n\u00a0 }\r\n\u00a0 my $timestamp = time;\r\n\u00a0 print \"[$timestamp] PROCESS_SERVICE_CHECK_RESULT;adslmodem;ADSL sync;$returncode;$status|$performance\\n\";\r\n}<\/pre>\n<p>The above Perl script is intended to be run from a shell script wrapper that makes the Perl script work more like a daemon, and sends the Perl script&#8217;s output to a useful place:<\/p>\n<pre>$ cat \/opt\/local\/libexec\/nagios\/check_adsl_state\r\n#!\/bin\/sh\r\n\r\nif [ -f \/opt\/local\/var\/nagios\/adsl-stats.pid ]\r\nthen\r\n\u00a0 kill -0 `cat \/opt\/local\/var\/nagios\/adsl-stats.pid` || \/bin\/rm \/opt\/local\/var\/nagios\/adsl-stats.pid\r\nfi\r\n\r\nif [ ! -f \/opt\/local\/var\/nagios\/adsl-stats.pid ]\r\nthen\r\n\u00a0 \/usr\/bin\/perl \/opt\/local\/libexec\/nagios\/adsl-stats.pl &gt; \/opt\/local\/var\/nagios\/rw\/nagios.cmd &amp;\r\n\u00a0 echo $! &gt; \/opt\/local\/var\/nagios\/adsl-stats.pid\r\n\u00a0 sleep 2\r\nfi\r\n\r\nif [ -f \/opt\/local\/var\/nagios\/adsl-stats.pid ]\r\nthen\r\n\u00a0 kill -USR1 `cat \/opt\/local\/var\/nagios\/adsl-stats.pid`\r\nfi<\/pre>\n<p>In turn, a Cron job ensures that the daemon is running, and that it probes the ADSL modem for statistics once a minute:<\/p>\n<pre>$ crontab -l\r\n* * * * * \/opt\/local\/libexec\/nagios\/check_adsl_state<\/pre>\n<p>With all this in place, the file <strong>\/opt\/local\/var\/nagios\/rw\/nagios.cmd<\/strong> is filled with lines like this:<\/p>\n<pre>[1374099781] PROCESS_SERVICE_CHECK_RESULT;adslmodem;ADSL sync;0;ADSL2 Fast No Defect Showtime 1878\/386kbps |'snr-down'=13.1dB 'snr-up'=12.0dB 'atten-down'=33.0dB 'atten-up'=27.9dB 'power-down'=17.4dB 'power-up'=12.6dB 'maxrate-down'=2532kbps 'maxrate-up'=430kbps 'rate-down'=1878kbps 'rate-up'=386kbps \r\n[1374099841] PROCESS_SERVICE_CHECK_RESULT;adslmodem;ADSL sync;0;ADSL2 Fast No Defect Showtime 1878\/386kbps |'snr-down'=13.1dB 'snr-up'=12.0dB 'atten-down'=33.0dB 'atten-up'=27.9dB 'power-down'=17.4dB 'power-up'=12.6dB 'maxrate-down'=2572kbps 'maxrate-up'=430kbps 'rate-down'=1878kbps 'rate-up'=386kbps<\/pre>\n<p>This format is dictated by the Nagios <a title=\"Nagios manual: passive checks\" href=\"http:\/\/nagios.sourceforge.net\/docs\/3_0\/passivechecks.html\">passive check<\/a> feature.\u00a0 Passive checks are useful when you have an external process that periodically dumps information to your Nagios instance.\u00a0 In this case, that external process is the Perl script.\u00a0 The file <strong>\/opt\/local\/var\/nagios\/rw\/nagios.cmd<\/strong> is monitored and periodically flushed by Nagios, and each line updates the state of a monitored service.<\/p>\n<p>The Nagios host configuration for the ADSL modem accepts passive checks, and if there hasn&#8217;t been an update in 5 minutes, flips the state to <strong>UNKNOWN<\/strong> (3) to prevent stale information:<\/p>\n<pre>define host {\r\n\u00a0 use\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0  generic-switch\r\n\u00a0 host_name\u00a0\u00a0 \u00a0adslmodem\r\n\u00a0 alias\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0adslmodem\r\n\u00a0 address\u00a0\u00a0 \u00a0\u00a0 192.168.1.1\r\n}\r\n\r\ndefine command {\r\n\u00a0 command_name check_adslmodem\r\n\u00a0 command_line $USER1$\/check_dummy 3\r\n}\r\n\r\ndefine service {\r\n\u00a0 use local-service,graphed-service\r\n\u00a0 host_name adslmodem\r\n\u00a0 service_description ADSL sync\r\n\u00a0 check_command check_adslmodem\r\n\u00a0 active_checks_enabled 0\r\n\u00a0 passive_checks_enabled 1\r\n\u00a0 check_freshness 1\r\n\u00a0 freshness_threshold 300 \u00a0\r\n}<\/pre>\n<p>On the Nagios web page, the statistics are visible in the Performance Data:<\/p>\n<figure id=\"attachment_135\" aria-describedby=\"caption-attachment-135\" style=\"width: 625px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagios-adslmodem-web-page.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-135\" alt=\"Nagios webpage for ADSL sync\" src=\"https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagios-adslmodem-web-page-1024x805.png\" width=\"625\" height=\"491\" srcset=\"https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagios-adslmodem-web-page-1024x805.png 1024w, https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagios-adslmodem-web-page-300x236.png 300w, https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagios-adslmodem-web-page-624x490.png 624w, https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagios-adslmodem-web-page.png 1271w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><figcaption id=\"caption-attachment-135\" class=\"wp-caption-text\">Nagios webpage for ADSL sync<\/figcaption><\/figure>\n<p>Graphing the statistics seemed like an obvious next step.\u00a0 Ice Moon Prison uses <a title=\"nagiosgraph on Sourceforge\" href=\"http:\/\/nagiosgraph.sourceforge.net\/\">nagiosgraph<\/a>, which collects performance data and displays it in four simple line graphs showing, from top to bottom, the statistics for the last day, week, month and year. The graph of downstream rate (maximum and actual) shows that although the line has been stable (but poor) today, for the last week the rate has danced around frequently, with each jump in the rate corresponding to a renegotiation by the ADSL modem and an interruption of any connection that was open at the time. Over the last year there has been a slow but noticeable drop in the rate that could be attained.\u00a0 And on the 12th of this month, something very bad happened.<\/p>\n<figure id=\"attachment_136\" aria-describedby=\"caption-attachment-136\" style=\"width: 625px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagiosgraph-of-downstream-speeds.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-136\" alt=\"nagiosgraph of downstream speeds\" src=\"https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagiosgraph-of-downstream-speeds-758x1024.png\" width=\"625\" height=\"844\" srcset=\"https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagiosgraph-of-downstream-speeds-758x1024.png 758w, https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagiosgraph-of-downstream-speeds-222x300.png 222w, https:\/\/www.icemoonprison.com\/blog\/wp-content\/uploads\/2013\/07\/Nagiosgraph-of-downstream-speeds.png 816w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><figcaption id=\"caption-attachment-136\" class=\"wp-caption-text\">The 12th was not a good day<\/figcaption><\/figure>\n<p>Today, Ice Moon Prison has to keep staff on-site while a technician comes to diagnose the copper line. We will be showing the technician these graphs to dispel any notion in their mind that Ice Moon Prison is imagining things.<\/p>\n<p><strong>UPDATE<\/strong>: A week later, Telstra agreed that there was enough line noise to warrant connecting Ice Moon Prison to a different copper pair.\u00a0 This resolved the problem instantly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here at Ice Moon Prison, we are blessed with an ADSL2+ lifeline to the Internet.\u00a0 At the same time, we are cursed with degrading copper and have seen a gradual decline in our sync speeds over the last two years. To monitor the situation, and to provide ammunition to use when technicians doubt our sincerity, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[5],"tags":[25,27,26],"class_list":["post-134","post","type-post","status-publish","format-standard","hentry","category-nagios","tag-adsl","tag-expect","tag-perl"],"_links":{"self":[{"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/posts\/134","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/comments?post=134"}],"version-history":[{"count":4,"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":257,"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/posts\/134\/revisions\/257"}],"wp:attachment":[{"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icemoonprison.com\/blog\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}