Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
d322845589 | |||
fef495ff7b |
11
HISTORY
11
HISTORY
@ -1,3 +1,14 @@
|
|||||||
|
0.5 - 2014-08-15
|
||||||
|
Added a check to see if cURL was successful in
|
||||||
|
retrieving the XML-file. If it was not, then exit
|
||||||
|
with a UNKNOWN state and print the cURL error message.
|
||||||
|
|
||||||
|
0.4 - 2014-08-09
|
||||||
|
Added /u modifier to more preg_matches for UTF-8
|
||||||
|
Replaced a-zåäö with \p{L}
|
||||||
|
Fixed a couple of spelling errors and missing words
|
||||||
|
Replaced $program with PROGRAM on line 122
|
||||||
|
|
||||||
0.3 - 2014-08-03
|
0.3 - 2014-08-03
|
||||||
Added /u modifier to the preg_match for UTF-8
|
Added /u modifier to the preg_match for UTF-8
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ define ("CRITICAL", 2);
|
|||||||
define ("UNKNOWN", 3);
|
define ("UNKNOWN", 3);
|
||||||
|
|
||||||
// Define version and program
|
// Define version and program
|
||||||
define ("VERSION", 0.2);
|
define ("VERSION", 0.5);
|
||||||
define ("PROGRAM", $argv[0]);
|
define ("PROGRAM", $argv[0]);
|
||||||
|
|
||||||
// Function for printing usage
|
// Function for printing usage
|
||||||
@ -116,10 +116,10 @@ if ($district == 'list')
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the district exists
|
// Check if the district exists
|
||||||
if (!preg_grep("/^$district$/", $availDistricts))
|
if (!preg_grep("/^$district$/u", $availDistricts))
|
||||||
{
|
{
|
||||||
print "$district does not exists\n";
|
print "$district does not exists\n";
|
||||||
print "List all avaliable districts by \"$program 'list'\"\n";
|
print "List all avaliable districts by \"" . PROGRAM . " 'list'\"\n";
|
||||||
exit(UNKNOWN);
|
exit(UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,19 +129,28 @@ if (!preg_grep("/^$district$/", $availDistricts))
|
|||||||
$ch = curl_init("http://www.smhi.se/weatherSMHI2/varningar/smhi_alla_varningar.xml");
|
$ch = curl_init("http://www.smhi.se/weatherSMHI2/varningar/smhi_alla_varningar.xml");
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
$data = curl_exec($ch);
|
curl_setopt($ch, CURLOPT_FAILONERROR, true);
|
||||||
|
// check if curl failed and bail out if it did
|
||||||
|
if (($data = curl_exec($ch)) === false)
|
||||||
|
{
|
||||||
|
print curl_error($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
exit(UNKNOWN);
|
||||||
|
}
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
//print "\n$data\n"; // for testing purposes (uncomment to view xml-file)
|
||||||
|
|
||||||
// Regex the area (1st paranthesis is area, 2nd is warning class, 3rd is warning msg)
|
// Regex the area (1st paranthesis is area, 2nd is warning class, 3rd is warning msg)
|
||||||
preg_match("/($district)(?:: )(?:Varning klass )([1-3]+)(?:,\s)([-a-z0-9åäö.,&\s]*)/iu",
|
preg_match("/($district)(?:: )(?:Varning klass )([1-3]+)(?:,\s)([-0-9\p{L}.,&\s]*)/iu",
|
||||||
$data, $matches);
|
$data, $matches);
|
||||||
|
|
||||||
// Count how many warnings are issued and issue a critical if more than one
|
// Count how many warnings are issued and issue a critical if more than one
|
||||||
preg_match_all("/$district/", $data, $counts);
|
preg_match_all("/$district/u", $data, $counts);
|
||||||
$numberMatches = (count($counts[0]));
|
$numberMatches = (count($counts[0]));
|
||||||
if ($numberMatches > 1)
|
if ($numberMatches > 1)
|
||||||
{
|
{
|
||||||
print "More than one warning are issued for $district, check smhi.se!";
|
print "More than one warning is issued for $district, check smhi.se!";
|
||||||
exit(CRITICAL);
|
exit(CRITICAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +169,7 @@ else
|
|||||||
switch ($warnLevel)
|
switch ($warnLevel)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
print "No warnings issued $district";
|
print "No warnings issued for $district";
|
||||||
exit(OK);
|
exit(OK);
|
||||||
case 1:
|
case 1:
|
||||||
print "Class 1 warning issued for $district: $warnMsg";
|
print "Class 1 warning issued for $district: $warnMsg";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user