| 1 | 
 <?php | 
 
 
 
 
 
 | 2 | 
  | 
 
 
 
 
 
 | 3 | 
 # Navigation for the i-scream alerts. | 
 
 
 
 
 
 | 4 | 
 # pjm2@ukc.ac.uk | 
 
 
 
 
 
 | 5 | 
 # | 
 
 
 
 
 
 | 6 | 
 # CONFIGURABLE CONSTANTS: - | 
 
 
 
 
 
 | 7 | 
  | 
 
 
 
 
 
 | 8 | 
 include("alerts_config.inc.php"); | 
 
 
 
 
 
 | 9 | 
  | 
 
 
 
 
 
 | 10 | 
 # | 
 
 
 
 
 
 | 11 | 
 # END CONFIGURATION | 
 
 
 
 
 
 | 12 | 
  | 
 
 
 
 
 
 | 13 | 
 include("iutils.inc.php"); | 
 
 
 
 
 
 | 14 | 
  | 
 
 
 
 
 
 | 15 | 
 function printLine($title) { | 
 
 
 
 
 
 | 16 | 
     echo "<hr style=\"color:#9999ff;\">"; | 
 
 
 
 
 
 | 17 | 
     echo "<b>$title</b>"; | 
 
 
 
 
 
 | 18 | 
 } | 
 
 
 
 
 
 | 19 | 
  | 
 
 
 
 
 
 | 20 | 
 function getValue($value, $alert) { | 
 
 
 
 
 
 | 21 | 
     preg_match("/$value=([^\,\}]*)[\,\}]/", $alert, $matches); | 
 
 
 
 
 
 | 22 | 
     return $matches[1]; | 
 
 
 
 
 
 | 23 | 
 } | 
 
 
 
 
 
 | 24 | 
  | 
 
 
 
 
 
 | 25 | 
 function printAlert($machine, $alert, $small="") { | 
 
 
 
 
 
 | 26 | 
  | 
 
 
 
 
 
 | 27 | 
     include("alerts_config.inc.php"); | 
 
 
 
 
 
 | 28 | 
  | 
 
 
 
 
 
 | 29 | 
     $alertLevelNum = getValue("alertLevel", $alert); | 
 
 
 
 
 
 | 30 | 
     $lastAlert = getValue("lastAlert", $alert); | 
 
 
 
 
 
 | 31 | 
     $thresholdLevel = getValue("thresholdLevel", $alert); | 
 
 
 
 
 
 | 32 | 
     $source = getValue("source", $alert); | 
 
 
 
 
 
 | 33 | 
     $thresholdValue = getValue("thresholdValue", $alert); | 
 
 
 
 
 
 | 34 | 
     $value = getValue("value", $alert); | 
 
 
 
 
 
 | 35 | 
     $attributeName = getValue("attributeName", $alert); | 
 
 
 
 
 
 | 36 | 
     $timeTillNextAlert = getValue("timeTillNextAlert", $alert); | 
 
 
 
 
 
 | 37 | 
     $initialAlertTime = getValue("initialAlertTime", $alert); | 
 
 
 
 
 
 | 38 | 
  | 
 
 
 
 
 
 | 39 | 
     if ($thresholdLevel == "1") { | 
 
 
 
 
 
 | 40 | 
         $thresholdLevel = "Lower"; | 
 
 
 
 
 
 | 41 | 
     } | 
 
 
 
 
 
 | 42 | 
     else if ($thresholdLevel == "2") { | 
 
 
 
 
 
 | 43 | 
         $thresholdLevel = "Upper"; | 
 
 
 
 
 
 | 44 | 
     } | 
 
 
 
 
 
 | 45 | 
     else { | 
 
 
 
 
 
 | 46 | 
         $thresholdLevel = "Normal"; | 
 
 
 
 
 
 | 47 | 
     } | 
 
 
 
 
 
 | 48 | 
  | 
 
 
 
 
 
 | 49 | 
     $alertColour = $alertLevelColours[$alertLevelNum]; | 
 
 
 
 
 
 | 50 | 
     $alertLevel = $alertLevelNames[$alertLevelNum]; | 
 
 
 
 
 
 | 51 | 
     $initialAlertTime = strftime("%x %X", intval($initialAlertTime / 1000)); | 
 
 
 
 
 
 | 52 | 
  | 
 
 
 
 
 
 | 53 | 
     if ($small == "true") { | 
 
 
 
 
 
 | 54 | 
         echo <<<EOT | 
 
 
 
 
 
 | 55 | 
             <tr> | 
 
 
 
 
 
 | 56 | 
              <td width="50"> | 
 
 
 
 
 
 | 57 | 
                 | 
 
 
 
 
 
 | 58 | 
              </td> | 
 
 
 
 
 
 | 59 | 
              <td align="left"> | 
 
 
 
 
 
 | 60 | 
               <img src="level$alertLevelNum.gif" width="41" height="9" border="0" alt="$alertLevel"> | 
 
 
 
 
 
 | 61 | 
              </td> | 
 
 
 
 
 
 | 62 | 
              <td align="left"> | 
 
 
 
 
 
 | 63 | 
               <font size="3" color="$alertColour"><b>$alertLevel</b></font> | 
 
 
 
 
 
 | 64 | 
              </td> | 
 
 
 
 
 
 | 65 | 
              <td align="left"> | 
 
 
 
 
 
 | 66 | 
               <font size="3">$attributeName</font> | 
 
 
 
 
 
 | 67 | 
              </td> | 
 
 
 
 
 
 | 68 | 
              <td> | 
 
 
 
 
 
 | 69 | 
                 | 
 
 
 
 
 
 | 70 | 
              </td> | 
 
 
 
 
 
 | 71 | 
             </tr> | 
 
 
 
 
 
 | 72 | 
 EOT; | 
 
 
 
 
 
 | 73 | 
     } | 
 
 
 
 
 
 | 74 | 
     else { | 
 
 
 
 
 
 | 75 | 
         echo <<<EOT | 
 
 
 
 
 
 | 76 | 
          | 
 
 
 
 
 
 | 77 | 
         <table border="0" cellspacing="5" width="100%"> | 
 
 
 
 
 
 | 78 | 
           <tr> | 
 
 
 
 
 
 | 79 | 
             <td align="left" width="40%"> | 
 
 
 
 
 
 | 80 | 
               <img src="level$alertLevelNum.gif" width="41" height="9" border="0" alt="$alertLevel"> | 
 
 
 
 
 
 | 81 | 
               <font color="$alertColour" size="2"><b>$alertLevel</b></font> | 
 
 
 
 
 
 | 82 | 
             </td> | 
 
 
 
 
 
 | 83 | 
             <td align="right" width="60%"> | 
 
 
 
 
 
 | 84 | 
               <b>$attributeName</b> | 
 
 
 
 
 
 | 85 | 
             </td> | 
 
 
 
 
 
 | 86 | 
           </tr> | 
 
 
 
 
 
 | 87 | 
           <tr> | 
 
 
 
 
 
 | 88 | 
             <td align="right"><font size="2">Threshold:</font></td> | 
 
 
 
 
 
 | 89 | 
             <td align="left">$thresholdValue ($thresholdLevel)</td> | 
 
 
 
 
 
 | 90 | 
           </tr> | 
 
 
 
 
 
 | 91 | 
           <tr> | 
 
 
 
 
 
 | 92 | 
             <td align="right"><font size="2">Alert value:</font></td> | 
 
 
 
 
 
 | 93 | 
             <td align="left"><b>$value</b></td> | 
 
 
 
 
 
 | 94 | 
           </tr> | 
 
 
 
 
 
 | 95 | 
           <tr> | 
 
 
 
 
 
 | 96 | 
             <td align="right"><font size="2">Initially raised:</font></td> | 
 
 
 
 
 
 | 97 | 
             <td align="left">$initialAlertTime</td> | 
 
 
 
 
 
 | 98 | 
           </tr> | 
 
 
 
 
 
 | 99 | 
         </table> | 
 
 
 
 
 
 | 100 | 
              | 
 
 
 
 
 
 | 101 | 
 EOT; | 
 
 
 
 
 
 | 102 | 
         printLine(""); | 
 
 
 
 
 
 | 103 | 
     } | 
 
 
 
 
 
 | 104 | 
  | 
 
 
 
 
 
 | 105 | 
 } | 
 
 
 
 
 
 | 106 | 
  | 
 
 
 
 
 
 | 107 | 
 function printReports($machine, $small="") { | 
 
 
 
 
 
 | 108 | 
     # Get a list of all files in the machine's directory. | 
 
 
 
 
 
 | 109 | 
     include("alerts_config.inc.php"); | 
 
 
 
 
 
 | 110 | 
     $alertArray = getdirArray("$alertDirectory/$machine", 'rsort'); | 
 
 
 
 
 
 | 111 | 
     | 
 
 
 
 
 
 | 112 | 
     if ($small == "true") { | 
 
 
 
 
 
 | 113 | 
         echo <<<EOT | 
 
 
 
 
 
 | 114 | 
            <table border="0" cellpadding="2" cellspacing="0"> | 
 
 
 
 
 
 | 115 | 
             <tr> | 
 
 
 
 
 
 | 116 | 
              <td colspan="5"> | 
 
 
 
 
 
 | 117 | 
               <font size="+1"><b><a href="alerts.php?machine=$machine" style="color: black; text-decoration: none;">$machine</a></b></font> | 
 
 
 
 
 
 | 118 | 
              </td> | 
 
 
 
 
 
 | 119 | 
             </tr> | 
 
 
 
 
 
 | 120 | 
 EOT; | 
 
 
 
 
 
 | 121 | 
     } | 
 
 
 
 
 
 | 122 | 
     else { | 
 
 
 
 
 
 | 123 | 
         echo <<<EOT | 
 
 
 
 
 
 | 124 | 
              <p> </p> | 
 
 
 
 
 
 | 125 | 
              <table border="0" cellpadding="3" cellspacing="2" bgcolor="#000066" width="100%"> | 
 
 
 
 
 
 | 126 | 
                <tr> | 
 
 
 
 
 
 | 127 | 
                <td> | 
 
 
 
 
 
 | 128 | 
                 <font color="white"> | 
 
 
 
 
 
 | 129 | 
                  <b> | 
 
 
 
 
 
 | 130 | 
                   Current alerts for <a href="latest.php?machine=$machine" style="color: white">$machine</a> | 
 
 
 
 
 
 | 131 | 
                  </b> | 
 
 
 
 
 
 | 132 | 
                  <font size="2"> | 
 
 
 
 
 
 | 133 | 
                   <br>Sorted by time, latest first. | 
 
 
 
 
 
 | 134 | 
                  </font> | 
 
 
 
 
 
 | 135 | 
                 </font> | 
 
 
 
 
 
 | 136 | 
                </td> | 
 
 
 
 
 
 | 137 | 
               </tr> | 
 
 
 
 
 
 | 138 | 
               <tr> | 
 
 
 
 
 
 | 139 | 
                <td bgcolor="white"> | 
 
 
 
 
 
 | 140 | 
      | 
 
 
 
 
 
 | 141 | 
 EOT; | 
 
 
 
 
 
 | 142 | 
  | 
 
 
 
 
 
 | 143 | 
         printLine(""); | 
 
 
 
 
 
 | 144 | 
     } | 
 
 
 
 
 
 | 145 | 
     | 
 
 
 
 
 
 | 146 | 
     if ($alertArray != FALSE) { | 
 
 
 
 
 
 | 147 | 
  | 
 
 
 
 
 
 | 148 | 
         foreach($alertArray as $file_name) { | 
 
 
 
 
 
 | 149 | 
             $input = file("$alertDirectory/$machine/$file_name"); | 
 
 
 
 
 
 | 150 | 
             $input = $input[0]; | 
 
 
 
 
 
 | 151 | 
             $alerts[] = $input; | 
 
 
 
 
 
 | 152 | 
         } | 
 
 
 
 
 
 | 153 | 
         | 
 
 
 
 
 
 | 154 | 
         foreach ($alerts as $alert) { | 
 
 
 
 
 
 | 155 | 
             printAlert($machine, $alert, $small); | 
 
 
 
 
 
 | 156 | 
         } | 
 
 
 
 
 
 | 157 | 
     } | 
 
 
 
 
 
 | 158 | 
     else { | 
 
 
 
 
 
 | 159 | 
         if ($small != "true") { | 
 
 
 
 
 
 | 160 | 
             echo "There are currently no alerts held about <b>$machine</b>"; | 
 
 
 
 
 
 | 161 | 
             printLine(""); | 
 
 
 
 
 
 | 162 | 
         } | 
 
 
 
 
 
 | 163 | 
     } | 
 
 
 
 
 
 | 164 | 
  | 
 
 
 
 
 
 | 165 | 
     if ($small == "true") { | 
 
 
 
 
 
 | 166 | 
         echo "</table>"; | 
 
 
 
 
 
 | 167 | 
     } | 
 
 
 
 
 
 | 168 | 
     else { | 
 
 
 
 
 
 | 169 | 
         echo <<<EOT | 
 
 
 
 
 
 | 170 | 
              </td> | 
 
 
 
 
 
 | 171 | 
             </tr> | 
 
 
 
 
 
 | 172 | 
            </table> | 
 
 
 
 
 
 | 173 | 
 EOT; | 
 
 
 
 
 
 | 174 | 
     } | 
 
 
 
 
 
 | 175 | 
 } | 
 
 
 
 
 
 | 176 | 
  | 
 
 
 
 
 
 | 177 | 
  | 
 
 
 
 
 
 | 178 | 
 ?> | 
 
 
 
 
 
 | 179 | 
  | 
 
 
 
 
 
 | 180 | 
 <? include($titleHTML); ?> | 
 
 
 
 
 
 | 181 | 
  | 
 
 
 
 
 
 | 182 | 
 <? if (!$hideform) { ?> | 
 
 
 
 
 
 | 183 | 
  | 
 
 
 
 
 
 | 184 | 
 <? printLine("Latest alerts for hosts"); ?> | 
 
 
 
 
 
 | 185 | 
  | 
 
 
 
 
 
 | 186 | 
 <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> | 
 
 
 
 
 
 | 187 | 
 <? | 
 
 
 
 
 
 | 188 | 
  | 
 
 
 
 
 
 | 189 | 
     $file_array = getdirArray($alertDirectory,'asort'); | 
 
 
 
 
 
 | 190 | 
     print "<select size=\"1\" name=\"machine\">"; | 
 
 
 
 
 
 | 191 | 
     if ($machine) { ?> | 
 
 
 
 
 
 | 192 | 
         <option selected value="<? echo $machine ?>"><? echo $machine ?></option> | 
 
 
 
 
 
 | 193 | 
         <option value="">----------------</option> | 
 
 
 
 
 
 | 194 | 
     <? } | 
 
 
 
 
 
 | 195 | 
     foreach ($file_array as $file_name) { | 
 
 
 
 
 
 | 196 | 
         #if (is_dir($file_name)) { | 
 
 
 
 
 
 | 197 | 
             print "<option value=\"$file_name\">$file_name</option>"; | 
 
 
 
 
 
 | 198 | 
         #} | 
 
 
 
 
 
 | 199 | 
     } | 
 
 
 
 
 
 | 200 | 
     print "</select>"; | 
 
 
 
 
 
 | 201 | 
  | 
 
 
 
 
 
 | 202 | 
 ?> | 
 
 
 
 
 
 | 203 | 
  <input type="hidden" name="small" value="<?=$small?>"> | 
 
 
 
 
 
 | 204 | 
  <input type="submit" name="submit" value="Display"> | 
 
 
 
 
 
 | 205 | 
 </form> | 
 
 
 
 
 
 | 206 | 
  | 
 
 
 
 
 
 | 207 | 
 <? } ?> | 
 
 
 
 
 
 | 208 | 
  | 
 
 
 
 
 
 | 209 | 
 <? if ($machine) { | 
 
 
 
 
 
 | 210 | 
  | 
 
 
 
 
 
 | 211 | 
        printLine(""); | 
 
 
 
 
 
 | 212 | 
  | 
 
 
 
 
 
 | 213 | 
        if ($machine == "ALL") { | 
 
 
 
 
 
 | 214 | 
            $machine_array = getdirArray($alertDirectory, 'asort'); | 
 
 
 
 
 
 | 215 | 
            if ($machine_array != FALSE) { | 
 
 
 
 
 
 | 216 | 
                foreach ($machine_array as $machine) { | 
 
 
 
 
 
 | 217 | 
                    printReports($machine, $small); | 
 
 
 
 
 
 | 218 | 
                } | 
 
 
 
 
 
 | 219 | 
            } | 
 
 
 
 
 
 | 220 | 
        } | 
 
 
 
 
 
 | 221 | 
        else { | 
 
 
 
 
 
 | 222 | 
            printReports($machine, $small); | 
 
 
 
 
 
 | 223 | 
        } | 
 
 
 
 
 
 | 224 | 
         | 
 
 
 
 
 
 | 225 | 
    } | 
 
 
 
 
 
 | 226 | 
    else { | 
 
 
 
 
 
 | 227 | 
        printLine(""); | 
 
 
 
 
 
 | 228 | 
    } | 
 
 
 
 
 
 | 229 | 
  | 
 
 
 
 
 
 | 230 | 
 ?> | 
 
 
 
 
 
 | 231 | 
  | 
 
 
 
 
 
 | 232 | 
 <? include($bottomHTML); ?> |