='$mon_time' and days like '%$today%'"; $result2 = db_query($query2); list($tmp_total_nodes) = db_fetch_array($result2); if ($total_down_count > 0) { $percent = 100 * (1 - ($total_down_count / $tmp_total_nodes)); $percent = round($percent, 2); if ($percent < 0) { $percent = 0; } } else { $percent = 100; } ####### End Up/Down Percentile ####### Query DOWN nodes manually ####### function list_of_includes($dir) { // Returns array of file names from $dir $i=0; if ($use_dir = @opendir($dir)) { while (($file = readdir($use_dir)) !== false) { if (ereg("query_",$file)) { $includes_arr[$i] = "$file"; $i++; } } closedir($use_dir); } return $includes_arr; } $query_type_includes = list_of_includes($path_to_include); $queries_type_array = array(); foreach ($query_type_includes as $types) { include_once($path_to_include.$types); } function query_socket($description, $ipaddress, $port, $query_type, $snmp_comm, $url, $username, $pass, $ptime, $max_attempts) { GLOBAL $allow_refused; switch($query_type) { case "HTTP": $stat = http_query($description, $ipaddress, $port, $url, $username, $pass, $ptime); break; case "ICMP": $stat = icmp_query($description, $ipaddress, $ptime); break; case "TCP": $stat = tcp_query($description, $ipaddress, $port, $ptime); break; case "SNMP": $stat = snmp_query($description, $ipaddress, $snmp_comm, $ptime); break; case "UDP": $stat = udp_query($description, $ipaddress, $port, $ptime); break; } return $stat; } function mailer($id, $mail_id, $status, $status_msg, $now, $sender, $downtime) { GLOBAL $detailed_email,$qtime; $query = "SELECT email FROM mail_group WHERE id='".$mail_id."'"; $result = db_query($query); while ($r = db_fetch_array($result)) { $email=$r["email"]; $query_comments = "SELECT description,ipaddress,comments FROM objects WHERE id='".$id."'"; $result_comments = db_query($query_comments); list($id_description,$id_ipaddress,$id_comments) = db_fetch_array($result_comments); if ($detailed_email == 1) { if ($id_comments) { $comments = "Comments: ".$id_comments; } $query_affected = "SELECT description FROM objects WHERE dependency='$id'"; $result_affected = db_query($query_affected); $num_rows_affected = db_num_rows($result_affected); unset($dir_affected); if ($num_rows_affected == 0) { $dir_affected = "NONE"; $affected_cnt = 0; } else { $affected_cnt = count_deps($id); $dir_affected = "\n"; while ($s = db_fetch_array($result_affected)) { $each_affected = $s["description"]; $dir_affected .= $each_affected."\n"; } } if (!$downtime) { $downtime = "Less than $qtime minute(s)"; } else { if ($downtime < 60) { $downtime = "$downtime Second(s)"; } elseif (($downtime >= 60) && ($downtime < 3600)) { $downtime = round($downtime/60, 2) . " Minute(s)"; } else { $downtime = round($downtime/3600, 2) . " Hour(s)"; } } if (!$status) { mail("$email","$id_description DOWN","$status_msg\nIP: $id_ipaddress\n\n$now\n\nDowntime: $downtime\n\nNodes Directly Affected: $dir_affected\nTotal Nodes Affected: $affected_cnt\n\n$comments","From:$sender"); } else { // Send a different message if up - we don't need as much info when it comes back up. mail("$email","$id_description UP","$status_msg\n$now\n\nTotal Downtime: $downtime","From:$sender"); } } else { if (!$status) { $subject = $id_description." DOWN"; } else { $subject = $id_description." UP"; } mail("$email","$subject","$status_msg\n$now","From:$sender"); } } } ######## End query of DOWN nodes ######## // If manually polling a node... if ((strip_tags($_GET["poll"]) == 1) && ($_GET["desc"]) && ($monitor_polling)) { $poll_desc = strip_tags(rtrim(ltrim($_GET["desc"]))); $query_poll = "SELECT id,description,ipaddress,port,query_type,mail_group,ptime,url,snmp_comm,auth_user,auth_pass FROM objects WHERE description='".$poll_desc."'"; $result_poll = db_query($query_poll); list($id,$desc,$ip,$port,$query_type,$mail_group,$ptime,$url,$snmp_comm,$http_user,$http_pass) = db_fetch_array($result_poll); $query_poll2 = "SELECT time,lastnotif FROM alert_log WHERE description='".$desc."' AND resolved='N'"; $result_poll2 = db_query($query_poll2); list($went_down,$lastnotif) = db_fetch_array($result_poll2); $poll = query_socket($desc, $ip, $port, $query_type, $snmp_comm, $url, $http_user, $http_pass, $ptime, 1); if ($poll[0]) { $downtime = (mktime() - $went_down); $query2 = "UPDATE alert_log SET downtime='".$downtime."',resolved='Y' WHERE description='".$desc."' AND resolved='N'"; $result2 = db_query($query2); $stat = $poll[0]; $stat_msg = $poll[1]; $now = date("m-d-Y g:i:s a", mktime()); if ($firstmail == 0) { $out = mailer($id, $mail_group, $stat, $stat_msg, $now, $sender, $downtime); } else if ($firstmail > 0 && ($al_lastnotif > $al_start_time)) { $out = mailer($id, $mail_group, $stat, $stat_msg, $now, $sender, $downtime); } } unset($poll_desc,$poll_time,$desc,$ip,$port,$query_type,$mail_group,$ptime,$url,$snmp_comm,$http_user,$http_pass,$downtime,$went_down,$stat,$stat_msg,$id,$out); if (!$_GET["iframe"]) { print ''; } } if (!$_GET["iframe"]) { echo ' Node Runner - Network Dashboard
'; } if (($status_stats == 1) && (!$_GET["iframe"])) { echo '

Node Statistics Snapshot:

• Current Network Time: '.date("g:i:s a",mktime()).'
• Network Endpoints: '.$server_count.' (Enabled)
• Non-Endpoints: '.intval($total_nodes - $server_count).' (Enabled)
• Total Network Nodes: '.$total_nodes.'


• Node Runner Query Interval: '.$qtime.' Minutes
• Oldest Historical Data: '.$oldest_timestamp.'

'; } // Show currently down $query4 = "SELECT id,description,downtime,ipaddress,port,query_type,url FROM alert_log WHERE resolved='N' ORDER BY description ASC"; $result4 = db_query($query4); $disp_downcount = db_num_rows($result4); if ($disp_downcount>0) { $down_desc_array = array(); if (!$_GET["iframe"]) { echo '

Current Outages:

'; } $i=1; while ($r = db_fetch_array($result4)) { $id = $r["id"]; $description = $r["description"]; if (($truncate_at > 0) && (strlen($description) > ($truncate_at + 3))) { $trunc_description = substr($description,0,$truncate_at)."..."; } else { $trunc_description = $description; } array_push($down_desc_array, $trunc_description); $desc = urlencode($description); $downtime = $r["downtime"]; $ipaddress = $r["ipaddress"]; $port = $r["port"]; $query_type = $r["query_type"]; $url = $r["url"]; if ($monitor_polling) { // polling may be disabled on the status monitor $out .= ''.$i.'. '. $trunc_description .'
'; $out .= '(CLICK TO POLL MANUALLY)'; } else { $out .= ''. $trunc_description .'
'; } $out .= '

IP: '. $ipaddress .' - '; if (($query_type == 'SNMP') || ($query_type == 'ICMP')) { $out .= $query_type; } else { $out .= $query_type.' Port: '. $port; } $out .= '
'; $out .= ''; if ($downtime < 60) { $downtime = "Less than $qtime Minute(s)"; } else if (($downtime >= 60) && ($downtime < 3600)) { $downtime = round($downtime/60, 2) . " Minute(s)"; } else { $downtime = round($downtime/3600, 2) . " Hour(s)"; } $out .= 'DOWNTIME: '. $downtime .'

'; $out .= '

'; $query4a = "SELECT id FROM objects WHERE description='$description'"; $result4a = db_query($query4a); list($id4a) = db_fetch_array($result4a); $query4b = "SELECT description FROM objects WHERE dependency='$id4a'"; $result4b = db_query($query4b); $num_rows4b = db_num_rows($result4b); if ($num_rows4b>0) { $out .= "DIRECTLY AFFECTED: ".$num_rows4b."
"; unset($cnt); $cnt2 = count_deps($id4a); $out .= "TOTAL AFFECTED: ". $cnt2 ."


"; } else { $out .= '

'; } $i++; } // end while if ($_GET["iframe"]) { echo '

'.$out.'

'.$out.'

'.$out.'
'; } if (($disp_downcount>4) && (!$_GET["iframe"])) { // Set up scrolling marquee because list will be too long. echo ' '; } else if (!$_GET["iframe"]) { // Just echo the output. echo $out; } if (!$_GET["iframe"]) { echo '
'; } } // Show recently failed if (($show_recent) && ($disp_downcount <= 3) && (!$_GET["iframe"])) { if ($disp_downcount == 3) { $recent_limit = 1; } else if ($disp_downcount == 2) { $recent_limit = 2; } else if ($disp_downcount == 1) { $recent_limit = 3; } else if (!$disp_downcount) { $recent_limit = 7; } echo '

Recent Outages:

'; $query = "SELECT description,time,downtime FROM alert_log WHERE downtime>0 ORDER BY lastnotif DESC LIMIT ".$recent_limit.""; $result = db_query($query); while ($r = db_fetch_array($result)) { $rec_desc = $r["description"]; if (($truncate_at > 0) && (strlen($rec_desc) > ($truncate_at + 3))) { $trunc_rec_desc = substr($rec_desc,0,$truncate_at)."..."; } else { $trunc_rec_desc = $rec_desc; } $rec_time = $r["time"]; $rec_datetime = date("m-d-Y g:i:s a",$rec_time); $rec_downtime = $r["downtime"]; if ($rec_downtime < 60) { $rec_downtime = $rec_downtime.' second(s)'; } elseif (($rec_downtime >= 60) && ($rec_downtime < 3600)) { $rec_downtime = round($rec_downtime/60, 2) . ' minute(s)'; } else { $rec_downtime = round($rec_downtime/3600, 2) . ' hour(s)'; } echo '• '.$trunc_rec_desc.'
  '.$rec_datetime.'
  DOWNTIME: '.$rec_downtime.'

'; } echo '
'; } if (!$_GET["iframe"]) { echo '
'; } if (!$percent) { $bgcolor = "#FF0000"; $fontcolor = "#FFFFFF"; $comment = "FUBAR"; } else { switch ($percent) { case ($percent == 100): $bgcolor = "#00FF00"; $fontcolor = "#000000"; $comment = "BLISS"; break; case (($percent < 100) && ($percent >= 75)): $bgcolor = "#FFFF00"; $fontcolor = "#000000"; $comment = "CONCERN"; break; case (($percent < 75) && ($percent >= 50)): $bgcolor = "#FF8000"; $fontcolor = "#000000"; $comment = "PANIC"; break; case ($percent <= 49): $bgcolor = "#FF0000"; $fontcolor = "#FFFFFF"; $comment = "FUBAR"; break; } //end switch } if (!$_GET["iframe"]) { echo ' '; } if (($percent != 100) && (!$_GET["iframe"])) { echo '

NETWORK: '. $percent .'%

('. $comment .')


'; } else if (($percent == 100) && (!$_GET["iframe"])) { echo '

100%  BLISS
99-75%  CONCERN
74-50%  PANIC
49-0%  FUBAR
'; } if (!$_GET["iframe"]) { echo '
Powered by Node Runner v'.$nr_ver.' Open Source Network Monitor.  This page will refresh every '. $dash_refrate .' seconds.
'; } ?>