PageRenderTime 55ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/polling/current.inc.php

https://github.com/observernms/core
PHP | 59 lines | 43 code | 13 blank | 3 comment | 13 complexity | cec7ab9e2cc07e92ffd7cd9217c5af81 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. <?php
  2. $query = "SELECT * FROM current WHERE device_id = '" . $device['device_id'] . "'";
  3. $current_data = mysql_query($query);
  4. while($dbcurrent = mysql_fetch_array($current_data)) {
  5. echo("Checking current " . $dbcurrent['current_descr'] . "... ");
  6. #$current_cmd = $config['snmpget'] . " -M ".$config['mibdir'] . " -m SNMPv2-MIB -O Uqnv -" . $device['snmpver'] . " -c " . $device['community'] . " " . $device['hostname'].":".$device['port'] . " " . $dbcurrent['current_oid'] . "|grep -v \"No Such Instance\"";
  7. #$current = trim(shell_exec($current_cmd));
  8. $current = snmp_get($device, $dbcurrent['current_oid'], "SNMPv2-MIB");
  9. if ($dbcurrent['current_precision'])
  10. {
  11. $current = $current / $dbcurrent['current_precision'];
  12. }
  13. $currentrrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("current-" . $dbcurrent['current_descr'] . ".rrd");
  14. if (!is_file($currentrrd)) {
  15. `rrdtool create $currentrrd \
  16. --step 300 \
  17. DS:current:GAUGE:600:-273:1000 \
  18. RRA:AVERAGE:0.5:1:1200 \
  19. RRA:MIN:0.5:12:2400 \
  20. RRA:MAX:0.5:12:2400 \
  21. RRA:AVERAGE:0.5:12:2400`;
  22. }
  23. echo($current . " A\n");
  24. rrdtool_update($currentrrd,"N:$current");
  25. # FIXME also warn when crossing WARN level!!
  26. if($dbcurrent['current_current'] > $dbcurrent['current_limit_low'] && $current <= $dbcurrent['current_limit_low'])
  27. {
  28. if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
  29. $msg = "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'] . " is " . $current . "A (Limit " . $dbcurrent['current_limit'];
  30. $msg .= "A) at " . date($config['timestamp_format']);
  31. mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'], $msg, $config['email_headers']);
  32. echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['current_descr'] . "\n");
  33. log_event('Current ' . $dbcurrent['current_descr'] . " under threshold: " . $current . " A (< " . $dbcurrent['current_limit_low'] . " A)", $device['device_id'], 'current', $current['current_id']);
  34. }
  35. else if($dbcurrent['current_current'] < $dbcurrent['current_limit'] && $current >= $dbcurrent['current_limit'])
  36. {
  37. if($device['sysContact']) { $email = $device['sysContact']; } else { $email = $config['email_default']; }
  38. $msg = "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'] . " is " . $current . "A (Limit " . $dbcurrent['current_limit'];
  39. $msg .= "A) at " . date($config['timestamp_format']);
  40. mail($email, "Current Alarm: " . $device['hostname'] . " " . $dbcurrent['current_descr'], $msg, $config['email_headers']);
  41. echo("Alerting for " . $device['hostname'] . " " . $dbcurrent['current_descr'] . "\n");
  42. log_event('Current ' . $dbcurrent['current_descr'] . " above threshold: " . $current . " A (> " . $dbcurrent['current_limit'] . " A)", $device['device_id'], 'current', $current['current_id']);
  43. }
  44. mysql_query("UPDATE current SET current_current = '$current' WHERE current_id = '" . $dbcurrent['current_id'] . "'");
  45. }
  46. ?>