I'm running SNMP Zenoss connected to mysql database.I'm using a PHP script to select the device that fails the most based on the severity level 5 and 4 for a particular year and month. The script works when I select severity = 5 but does not work when i have a mixture of 5 and 4.
Severity 5 is highest and 1 is the lowest. Table name is history.
-Column name called "devices" has all the device names.
-Column name called "events" has all the events that are generated.
-Column name called "severity" has severity levels from 5-1.
BELOW IS THE PHP SCRIPT THAT WORKS WHEN SEVERITY = 5
$yearNum= $_GET["year_num"];
$monthNum= $_GET["month_num"];
$filename = "exported_tickets.txt";
$Handle = fopen($filename, 'w');
mysql_connect("--.--.--.--", "username", "password") or die(mysql_error());
mysql_select_db("events") or die(mysql_error());
// Collects data from "history" table: filtering based on the year and month.
$result = mysql_query ("SELECT device,
count(*) AS number_of_events
from history
where severity = 5
AND MONTH(stateChange)= ".$monthNum." AND YEAR(stateChange) = ".$yearNum."
GROUP BY Device
ORDER BY number_of_events DESC LIMIT 10") or die(mysql_error());
fwrite($Handle, "device".", "."number_of_events"." \n");
// store the record of the table into $row
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
fwrite($Handle, $row["device"].", ".$row["number_of_events"]."\n");
}
mysql_free_result($result);
fclose($Handle);
BELOW IS THE PHP SCRIPT THAT DOES NOT WORK WHEN I HAVE A MIXTURE OF SEVERITY = 5 AND 4
$yearNum= $_GET["year_num"];
$monthNum= $_GET["month_num"];
$filename = "exported_tickets.txt";
$Handle = fopen($filename, 'w');
mysql_connect("--.--.--.--", "username", "password") or die(mysql_error());
mysql_select_db("events") or die(mysql_error());
// Collects data from "history" table: filtering based on the year and month.
$result = mysql_query ("SELECT device,
count(*) AS number_of_events
from history
where severity = 5
AND MONTH(stateChange)= ".$monthNum." AND YEAR(stateChange) = ".$yearNum."
GROUP BY Device
UNION ALL
SELECT device,
count(*) AS number_of_events
from history
where severity = 4
AND MONTH(stateChange)= ".$monthNum." AND YEAR(stateChange) = ".$yearNum."
GROUP BY Device
ORDER BY number_of_events DESC LIMIT 10") or die(mysql_error());
fwrite($Handle, "device".", "."number_of_events"." \n");
// store the record of the table into $row
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
fwrite($Handle, $row["device"].", ".$row["number_of_events"]."\n");
}
mysql_free_result($result);
fclose($Handle);
PLEASE HELP
Severity 5 is highest and 1 is the lowest. Table name is history.
-Column name called "devices" has all the device names.
-Column name called "events" has all the events that are generated.
-Column name called "severity" has severity levels from 5-1.
BELOW IS THE PHP SCRIPT THAT WORKS WHEN SEVERITY = 5
$yearNum= $_GET["year_num"];
$monthNum= $_GET["month_num"];
$filename = "exported_tickets.txt";
$Handle = fopen($filename, 'w');
mysql_connect("--.--.--.--", "username", "password") or die(mysql_error());
mysql_select_db("events") or die(mysql_error());
// Collects data from "history" table: filtering based on the year and month.
$result = mysql_query ("SELECT device,
count(*) AS number_of_events
from history
where severity = 5
AND MONTH(stateChange)= ".$monthNum." AND YEAR(stateChange) = ".$yearNum."
GROUP BY Device
ORDER BY number_of_events DESC LIMIT 10") or die(mysql_error());
fwrite($Handle, "device".", "."number_of_events"." \n");
// store the record of the table into $row
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
fwrite($Handle, $row["device"].", ".$row["number_of_events"]."\n");
}
mysql_free_result($result);
fclose($Handle);
BELOW IS THE PHP SCRIPT THAT DOES NOT WORK WHEN I HAVE A MIXTURE OF SEVERITY = 5 AND 4
$yearNum= $_GET["year_num"];
$monthNum= $_GET["month_num"];
$filename = "exported_tickets.txt";
$Handle = fopen($filename, 'w');
mysql_connect("--.--.--.--", "username", "password") or die(mysql_error());
mysql_select_db("events") or die(mysql_error());
// Collects data from "history" table: filtering based on the year and month.
$result = mysql_query ("SELECT device,
count(*) AS number_of_events
from history
where severity = 5
AND MONTH(stateChange)= ".$monthNum." AND YEAR(stateChange) = ".$yearNum."
GROUP BY Device
UNION ALL
SELECT device,
count(*) AS number_of_events
from history
where severity = 4
AND MONTH(stateChange)= ".$monthNum." AND YEAR(stateChange) = ".$yearNum."
GROUP BY Device
ORDER BY number_of_events DESC LIMIT 10") or die(mysql_error());
fwrite($Handle, "device".", "."number_of_events"." \n");
// store the record of the table into $row
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
fwrite($Handle, $row["device"].", ".$row["number_of_events"]."\n");
}
mysql_free_result($result);
fclose($Handle);
PLEASE HELP