Added a check to see if there's more than one warning

This commit is contained in:
2014-07-27 17:00:25 +02:00
parent 5cd5537f10
commit 9cbe7deedc
2 changed files with 13 additions and 1 deletions

13
check_smhiwarn.php Normal file → Executable file
View File

@@ -1,3 +1,4 @@
#!/usr/bin/php
<?php
// Define exit status
$ok = 0;
@@ -104,12 +105,22 @@ if (!preg_grep("/^$district$/", $availDistricts))
// Retrive the data
$data = file_get_contents("smhi_alla_varningar.xml");
//$data = file_get_contents("smhi_alla_varningar.xml"); //For testing purposes
$data = shell_exec("curl -s http://www.smhi.se/weatherSMHI2/varningar/smhi_alla_varningar.xml");
//Regex the area (1st parathentis is area, 2nd is warning class, 3rd is warning msg)
preg_match("/($district)(?:: )(?:Varning klass )([1-3]+)(?:,\s)([-a-z0-9åäö.,&\s]*)/i",
$data, $matches);
//Count how many warnings are issued and issue a critical if more than one
preg_match_all("/$district/", $data, $counts);
$numberMatches = (count($counts[0]));
if ($numberMatches > 1)
{
print "More than one warning are issued for $district, check smhi.se!";
exit($critical);
}
//Define the paranthesis
if (isset($matches[2]))
{