| 1 | <?php | 
 
 
 
 
 | 2 |  | 
 
 
 
 
 | 3 | include("alerts_config.inc.php"); | 
 
 
 
 
 | 4 |  | 
 
 
 
 
 | 5 | include("iutils.inc.php"); | 
 
 
 
 
 | 6 |  | 
 
 
 
 
 | 7 | function getValue($value, $alert) { | 
 
 
 
 
 | 8 | preg_match("/$value=([^\,\}]*)[\,\}]/", $alert, $matches); | 
 
 
 
 
 | 9 | return $matches[1]; | 
 
 
 
 
 | 10 | } | 
 
 
 
 
 | 11 |  | 
 
 
 
 
 | 12 | function printAlert($machine, $alert, $small="") { | 
 
 
 
 
 | 13 | include("alerts_config.inc.php"); | 
 
 
 
 
 | 14 |  | 
 
 
 
 
 | 15 | $alertLevelNum = getValue("alertLevel", $alert); | 
 
 
 
 
 | 16 | $lastAlert = getValue("lastAlert", $alert); | 
 
 
 
 
 | 17 | $thresholdLevel = getValue("thresholdLevel", $alert); | 
 
 
 
 
 | 18 | $source = getValue("source", $alert); | 
 
 
 
 
 | 19 | $thresholdValue = getValue("thresholdValue", $alert); | 
 
 
 
 
 | 20 | $value = getValue("value", $alert); | 
 
 
 
 
 | 21 | $attributeName = getValue("attributeName", $alert); | 
 
 
 
 
 | 22 | $timeTillNextAlert = getValue("timeTillNextAlert", $alert); | 
 
 
 
 
 | 23 | $initialAlertTime = getValue("initialAlertTime", $alert); | 
 
 
 
 
 | 24 |  | 
 
 
 
 
 | 25 | if ($thresholdLevel == "1") { | 
 
 
 
 
 | 26 | $thresholdLevel = "Lower"; | 
 
 
 
 
 | 27 | } | 
 
 
 
 
 | 28 | else if ($thresholdLevel == "2") { | 
 
 
 
 
 | 29 | $thresholdLevel = "Upper"; | 
 
 
 
 
 | 30 | } | 
 
 
 
 
 | 31 | else { | 
 
 
 
 
 | 32 | $thresholdLevel = "Normal"; | 
 
 
 
 
 | 33 | } | 
 
 
 
 
 | 34 |  | 
 
 
 
 
 | 35 | $alertLevel = $alertLevelNames[$alertLevelNum]; | 
 
 
 
 
 | 36 | setlocale(LC_TIME, "en_GB"); | 
 
 
 
 
 | 37 | $initialAlertTime = strftime("%x %X", intval($initialAlertTime / 1000)); | 
 
 
 
 
 | 38 |  | 
 
 
 
 
 | 39 | $alertLevel = strtoupper($alertLevel); | 
 
 
 
 
 | 40 |  | 
 
 
 
 
 | 41 | echo <<<EOT | 
 
 
 
 
 | 42 | <item> | 
 
 
 
 
 | 43 | <title> | 
 
 
 
 
 | 44 | $alertLevel: $machine: $attributeName | 
 
 
 
 
 | 45 | </title> | 
 
 
 
 
 | 46 | <link> | 
 
 
 
 
 | 47 | http://i-scream.cs.kent.ac.uk/alerts.php?machine=$machine | 
 
 
 
 
 | 48 | </link> | 
 
 
 
 
 | 49 | <description> | 
 
 
 
 
 | 50 | <pre> | 
 
 
 
 
 | 51 | Host: $source | 
 
 
 
 
 | 52 | Level: $alertLevel | 
 
 
 
 
 | 53 | What: $attributeName | 
 
 
 
 
 | 54 | Why: $value passed threshold $thresholdLevel:$thresholdValue | 
 
 
 
 
 | 55 | When: $initialAlertTime | 
 
 
 
 
 | 56 | </pre> | 
 
 
 
 
 | 57 | </description> | 
 
 
 
 
 | 58 | </item> | 
 
 
 
 
 | 59 | EOT; | 
 
 
 
 
 | 60 | } | 
 
 
 
 
 | 61 |  | 
 
 
 
 
 | 62 | function printReports($machine, $small="") { | 
 
 
 
 
 | 63 | # Get a list of all files in the machine's directory. | 
 
 
 
 
 | 64 | include("alerts_config.inc.php"); | 
 
 
 
 
 | 65 | $alertArray = getdirArray("$alertDirectory/$machine", 'rsort'); | 
 
 
 
 
 | 66 |  | 
 
 
 
 
 | 67 | if ($alertArray != FALSE) { | 
 
 
 
 
 | 68 | foreach($alertArray as $file_name) { | 
 
 
 
 
 | 69 | $input = file("$alertDirectory/$machine/$file_name"); | 
 
 
 
 
 | 70 | $input = $input[0]; | 
 
 
 
 
 | 71 | $alerts[] = $input; | 
 
 
 
 
 | 72 | } | 
 
 
 
 
 | 73 |  | 
 
 
 
 
 | 74 | foreach ($alerts as $alert) { | 
 
 
 
 
 | 75 | printAlert($machine, $alert, $small); | 
 
 
 
 
 | 76 | } | 
 
 
 
 
 | 77 | } | 
 
 
 
 
 | 78 | } | 
 
 
 
 
 | 79 | ?> | 
 
 
 
 
 | 80 |  | 
 
 
 
 
 | 81 | <?php | 
 
 
 
 
 | 82 | echo <<<EOT | 
 
 
 
 
 | 83 | <?xml version="1.0" encoding="iso-8859-1"?> | 
 
 
 
 
 | 84 | <rss version="0.91"> | 
 
 
 
 
 | 85 | <channel> | 
 
 
 
 
 | 86 | <title>i-scream alerts</title> | 
 
 
 
 
 | 87 | <link>http://i-scream.cs.kent.ac.uk/</link> | 
 
 
 
 
 | 88 | <description>Alerts being generated by the i-scream system</description> | 
 
 
 
 
 | 89 | EOT; | 
 
 
 
 
 | 90 | if (!$machine || $machine == "ALL") { | 
 
 
 
 
 | 91 | $machine_array = getdirArray($alertDirectory, 'asort'); | 
 
 
 
 
 | 92 | if ($machine_array != FALSE) { | 
 
 
 
 
 | 93 | foreach ($machine_array as $machine) { | 
 
 
 
 
 | 94 | printReports($machine, $small); | 
 
 
 
 
 | 95 | } | 
 
 
 
 
 | 96 | } | 
 
 
 
 
 | 97 | } | 
 
 
 
 
 | 98 | else { | 
 
 
 
 
 | 99 | printReports($machine, $small); | 
 
 
 
 
 | 100 | } | 
 
 
 
 
 | 101 | echo <<<EOT | 
 
 
 
 
 | 102 | </channel> | 
 
 
 
 
 | 103 | </rss> | 
 
 
 
 
 | 104 | EOT; | 
 
 
 
 
 | 105 | ?> |