{"id":202,"date":"2021-11-21T13:32:38","date_gmt":"2021-11-21T13:32:38","guid":{"rendered":"https:\/\/anthonyparkes.co.uk\/?p=202"},"modified":"2021-11-21T13:32:38","modified_gmt":"2021-11-21T13:32:38","slug":"downdetector-co-uk-nagios-script","status":"publish","type":"post","link":"https:\/\/anthonyparkes.co.uk\/?p=202","title":{"rendered":"Downdetector.co.uk Nagios Script"},"content":{"rendered":"\n<p>This is a PHP based script for monitoring Downdetector.co.uk on Nagios. It doesn&#8217;t use the paid API and just pulls the data it needs from the webpage. This means it is free to use.<\/p>\n\n\n\n<p>To use it just run PHP SCRIPTNAME SERVICE WarningLevel<br>example: PHP <em>check_downdetector.php facebook 100<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$service = $argv&#91;1];\n$reportswarning = $argv&#91;2];\nerror_reporting(0);\n$url = \"https:\/\/downdetector.co.uk\/status\/$service\/\";\n\n\nexec(\"curl $url > \/tmp\/$service.txt\");\n\n$d=0;\n$handle = fopen(\"\/tmp\/$service.txt\", \"r\");\nif ($handle) {\n    while (($line = fgets($handle)) !== false) {\n            if (strpos($line, \"data: &#91;\")) {\n                        if ($d == \"1\") { $lastreport = $last; }\n\n                    $d++;\n                    }\n            if (strpos($line, \"x: \")) {\n\n                    if ($d == \"1\" ) {\n                            \/\/\/ do something with reports\n                            $reports = $reports . $line;\n                            $last = $line;\n                    }\n\n                    if ($d == \"2\" ) {\n                    \/\/\/ do something with baseline\n                            $baseline = $baseline . $line;\n                            $last = $line;\n            }\n\n\n            }\n            \/\/$i++;\n    }\n    $lastbaseline = $last;\n    fclose($handle);\n}\n$piecesa = explode(\",\", $lastreport);\n$lastreport = $piecesa&#91;1];\n$lastreport = str_replace(\"y: \", \"\", $lastreport);\n$lastreport = str_replace(\" }\", \"\", $lastreport);\n$lastreport = str_replace(\" \", \"\", $lastreport);\n$piecesb = explode(\",\", $lastbaseline);\n$lastbaseline = $piecesb&#91;1];\n$lastbaseline = str_replace(\"y: \", \"\", $lastbaseline);\n$lastbaseline = str_replace(\" }\", \"\", $lastbaseline);\n$lastbaseline = str_replace(\" \", \"\", $lastbaseline);\nunlink(\"\/tmp\/$service.txt\");\nif ($reportswarning != \"\") { $warning = $reportswarning;  } else { $warning = $lastbaseline; }\nif ($lastreport > $warning) {\n        echo \"WARNING: $service is in a problem state with $lastreport reports and baseline of $lastbaseline warning: $warning | reports=$lastreport\";\n        exit(1);\n} else {\n        echo \"OK: $service reports are within limits  with $lastreport reports and baseline of $lastbaseline  warning: $warning | reports=$lastreport\";\n        exit(0);\n}\n\n?>\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This is a PHP based script for monitoring Downdetector.co.uk on Nagios. It doesn&#8217;t use the paid API and just pulls the data it needs from<\/p>\n","protected":false},"author":2,"featured_media":203,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"template-fullwidth.php","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=202"}],"version-history":[{"count":1,"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":204,"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions\/204"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=\/wp\/v2\/media\/203"}],"wp:attachment":[{"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anthonyparkes.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}