public static function recalWorkers() { $mysql = new MySQL(); $rs = $mysql->runQuery("select count(id) as cnt, frequency from monitors where active=1 group by frequency;"); $workers = 0.0; while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $workers += (double) $row['cnt'] / (double) $row['frequency']; } $workers = (int) ceil($workers) * 60; $mysql->runQuery("update settings set cronIterations={$workers};"); $mysql->close(); }
public function runPlugin($input = array()) { $output = Plugin::$output; ///set defaults for all output $t = new Timer(); $t->start(); try { $mysql = new MySQL($input['mysqlConnection']); $rs = $mysql->runQuery($input['testQuery']); if ($row = mysql_fetch_array($rs, MYSQL_NUM)) { $output['currentStatus'] = 1; $output['returnContent'] = "All normal\n" . $row[0]; $output['measuredValue'] = $row[0]; } else { $output['currentStatus'] = 0; $output['returnContent'] = "no results were returned for the query" . $input['testQuery']; } } catch (Exception $e) { $output['currentStatus'] = 0; $output['returnContent'] = "Query {$input['testQuery']} errored:\n" . $e->getMessage(); } $output['responseTimeMs'] = (int) $t->stop(); return $output; }
<tr> <td> <?php $id = array_key_exists('id', $_GET) ? (int) $_GET['id'] : 0; $del = array_key_exists('del', $_GET) ? (int) $_GET['del'] : 0; $copy = array_key_exists('cpy', $_GET) ? (int) $_GET['cpy'] : 0; $name = array_key_exists('name', $_POST) ? $_POST['name'] : ''; $frequency = array_key_exists('frequency', $_POST) ? (int) $_POST['frequency'] : 60; //60 seconds $notifyAdmin = array_key_exists('notifyAdmin', $_POST) ? (int) $_POST['notifyAdmin'] : 1; $pluginType = array_key_exists('pluginType', $_POST) ? $_POST['pluginType'] : ''; $pluginInput = array_key_exists('pluginInput', $_POST) ? $_POST['pluginInput'] : ''; $active = array_key_exists('active', $_POST) ? (int) $_POST['active'] : 1; $mysql = new MySQL(); if ($copy != 0 && $id != 0) { $mysql->runQuery("insert into monitors(name,frequency,notifyAdmin,currentStatus,pluginType,pluginInput,active) (select name,frequency,notifyAdmin,currentStatus,pluginType,pluginInput,active from monitors where id={$id});"); $id = $mysql->identity; Settings::recalWorkers(); header("Location: setupMonitor.php?id={$id}"); exit; } elseif ($name != '' && $id != 0) { //update $sql = "update monitors \n\t\tset name ='{$name}', \n\t\tfrequency={$frequency}, \n\t\tnotifyAdmin={$notifyAdmin},\n\t\tpluginType='{$pluginType}',\n\t\tpluginInput='" . mysql_real_escape_string($pluginInput, $mysql->mysqlCon) . "', \n\t active={$active} where id = {$id};"; //echo($sql); $mysql->runQuery($sql); Settings::recalWorkers(); header('Location: monitors.php'); exit; } elseif ($name != '') { //insert $sql = "insert into monitors (name,frequency,notifyAdmin,currentStatus,pluginType,pluginInput,active) values(\n\t'{$name}',\n\t{$frequency},\n\t{$notifyAdmin},\n\t1,\n\t'{$pluginType}',\n\t'" . mysql_real_escape_string($pluginInput, $mysql->mysqlCon) . "',\t\n\t{$active}\n\t);";
<table class="sortable" width="100%" border="0" cellpadding="1" cellspacing="2"> <tr class="sub"> <th align=center>Monitor</td> <th align=center>Plugin</td> <th align=center>Frequency</td> <th align=center>Status</td> <th align=center>Last Run</td> <th align=center>Last Error</td> <th align=center>Active</td> <th align=center>Notices</td> <th align=center>Reports</td> </tr> <!--<tbody class="grey">--> <?php $mysql = new MySQL(); $rs = $mysql->runQuery("\nselect *\nfrom monitors m\norder by active, name;\n"); while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { ?> <tr class="grey" bgcolor="#dddddd"> <td align="left"> <a href="setupMonitor.php?id=<?php echo urlencode($row['id']); ?> "><?php echo htmlspecialchars($row['name']); ?> </a></td> <td align="left"> <?php echo htmlspecialchars($row['pluginType']); ?> </td> <td align="left"> <?php
mysql_free_result($rs); ?> </table> </fieldset> <fieldset class="statField"> <legend>Current Issues</legend> <table class="dashboard" border="0" cellspacing="2" cellpadding="2"> <tr> <td><strong>When</strong></td> <td><strong>Monitor</strong></td> <td><strong>Measured Value</strong></td> </tr> <?php $mysql = new MySQL(); $rs = $mysql->runQuery("\nselect min(l.dateTime) as failureDateTime, l.measuredValue, m.name\nfrom monitors m \n inner join (\n select max(id) as id, monitorId\n from logging\n where status = 1\n group by monitorId\n ) le on le.monitorId = m.id\n inner join logging l on m.id = l.monitorId and le.id < l.id\n\nwhere m.currentStatus = 0 and l.status = 0\ngroup by m.name\norder by min(l.dateTime) desc limit 50;\n\t\t"); $none = true; while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $none = false; $whenText = Utilities::timeDiffString($row['failureDateTime']); echo "<tr>"; echo "<td>{$row['failureDateTime']} - ({$whenText})</td>"; echo "<td>" . htmlentities($row['name']) . "</td>"; echo "<td>" . $row['measuredValue'] . "</td>"; echo "</tr>"; } if ($none) { echo "<tr><td colspan=3>none</td></tr>"; } mysql_free_result($rs); ?>
echo $id; ?> log</td> </tr> </thead> <tr class="sub"> <td align=center>Event Time</td> <td align=center>Status</td> <td align=center>Response Time(ms)</td> <td align=center>Measured Value</td> </tr> <tbody class="grey"> <?php $mysql = new MySQL(); $rs = $mysql->runQuery("\nselect *\nfrom logging\nwhere monitorId = {$id}\norder by dateTime desc limit 2000;\n"); while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { ?> <tr bgcolor="#dddddd"> <td align="left"> <?php echo $row['dateTime']; ?> </td> <td align="left"> <span class="<?php if ($row['status'] == 1) { echo 'green'; } else { echo 'red'; } ?> "><?php
<body onload="setTimeout(function() { window.scrollTo(0, 1) }, 100);"> <h1>Current Issues</h1> <ul> <?php $mysql = new MySQL(); $rs = $mysql->runQuery("\nselect name, lastError\nfrom monitors \nwhere active = 1 and currentStatus = 0\norder by lastError desc;\n\t\t"); $none = true; while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $none = false; $whenText = Utilities::timeDiffString($row['lastError']); echo '<li><span>' . $row['name'] . ' (' . $whenText . ')</span></li>'; } if ($none) { echo '<li><span>no current issues</span></li>'; } echo '</ul>'; echo '<h1>Previous Issues</h1>'; echo '<ul>'; mysql_free_result($rs); $mysql = new MySQL(); $rs = $mysql->runQuery("\nselect name, lastError\nfrom monitors \nwhere active = 1 and currentStatus = 1\norder by lastError desc limit 10;\n\t\t"); while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $whenText = Utilities::timeDiffString($row['lastError']); echo '<li><span>' . $row['name'] . ' (' . $whenText . ')</span></li>'; } mysql_free_result($rs); ?> </ul> </body> </html>
$notifyAdmin = $row['notifyAdmin']; $mysql->runQuery("update monitors set lastRun=now() where id = {$id};"); $mysql->runQuery("UNLOCK TABLES;"); $mysql->close(); //echo("UNLOCKED\n"); $pluginClass = $pluginType . 'Plugin'; //run pluggin class_exists($pluginClass, false) or (include './plugins/' . $pluginType . '.plugin.php'); $input = Settings::parseIniString($pluginInput); eval('$inst = new ' . $pluginClass . '; $output = $inst->runPlugin($input);'); echo date('Y-m-d H:i:s') . "\t{$pluginType}\t{$id}\t{$name}\tStarted\n"; $mysql = new MySQL(); $t = new Timer(); $t->start(); $sql = sprintf('update monitors set currentStatus = %d where id = %d;', $output['currentStatus'], $id); $mysql->runQuery($sql); if ($output['currentStatus'] == 0) { $mysql->runQuery("update monitors set lastError=now() where id = {$id};"); } //notify anyone? $rs = $mysql->runQuery("select * from logging where monitorId = {$id} order by dateTime desc limit 1;"); if ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) { $previousStatus = $row['status']; } else { $previousStatus = 0; } //echo("prev: $previousStatus - current: $output[currentStatus]\n"); if ($notifyAdmin == 1 && $previousStatus != $output['currentStatus']) { $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = $settings['smtpServer'];