< Nagios
-->Nagios/Mediawiki
Check if a Mediawiki is up using Nagios[edit]
host definiton example[edit]
define host{ use linux-server host_name wiktionary alias en.wiktionary.org alias rr.knams.wikimedia.org address 91.198.174.2 } define host{ use linux-server host_name geist alias geist.s23.org address 84.16.233.231 }
service definitions example[edit]
###################### # SERVICE DEFINITIONS # WIKI ################ define service{ use s23-service host_name geist service_description WIKI S23 check_command check_wiki!s23.org notifications_enabled 1 } define service{ use friend-service host_name wiktionary service_description English Wiktionary check_command check_wiki!en.wiktionary.org notifications_enabled 1 }
check_wiki command[edit]
#!/usr/bin/php # Nagios probe to check if a Mediawiki really displays the Main_Page / Hauptseite # mutante / s23.org <?php error_reporting(E_ERROR | E_PARSE); ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'); $HOSTADDRESS=$argv[1]; $url="http://".$HOSTADDRESS."/wiki/"; $chkstr_pre="class=\"firstHeading\">"; $chkstr_en="Main Page"; $chkstr_de="Hauptseite"; $chkstr_pos="</h1>"; $buffer=file_get_contents($url); $statuscode=explode(" ",$http_response_header[0]); $statuscode=$statuscode[1]; $ok_codes=array("200","301","302"); if (!in_array($statuscode,$ok_codes)) { echo "CRITICAL. $HOSTADDRESS Wiki Main_Page down. - HTTP: $statuscode\n"; exit (2); } else { $pieces=explode($chkstr_pre,$buffer); $pieces=explode($chkstr_pos,$pieces[1]); # fix to make sure it works on different mediawiki versions (different html source) $pieces=explode(":",$pieces[0]); if ($pieces[1]!="") { $result=$pieces[1]; } else { $result=$pieces[0]; } if ($result==$chkstr_en OR $result==$chkstr_de) { echo "OK. $HOSTADDRESS Wiki Main_Page is up. - PARSE: $result - HTTP: $statuscode\n"; #echo "result: $result \n"; #echo "compar: $chkstr_en $chkstr_de "; exit (0); } else { echo "WARNING. $HOSTADDRESS Wiki Main_Page - PARSE: $result - HTTP: $statuscode\n"; exit (1); } } echo "UNKNOWN. Problem with check script. - PARSE: $result - HTTP: $statuscode\n"; exit (3); ?>