mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
more code cleanup
git-svn-id: http://www.observium.org/svn/observer/trunk@2519 61d68cd4-352d-0410-923a-c4978735b2b8
This commit is contained in:
50
irc.php
50
irc.php
@@ -23,16 +23,13 @@ echo "Timestamp Command\n";
|
||||
echo "----------------- ------- \n";
|
||||
|
||||
class observiumbot
|
||||
|
||||
{
|
||||
|
||||
|
||||
###
|
||||
# Get HELP!
|
||||
###
|
||||
function help_info(&$irc, &$data)
|
||||
{
|
||||
|
||||
global $config;
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Commands: !help, !log, !status, !version, !down, !port, !device, !listdevices");
|
||||
@@ -41,16 +38,13 @@ echo date("m-d-y H:i:s ");
|
||||
echo "HELP\n";
|
||||
|
||||
mysql_close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# Get status on !version
|
||||
###
|
||||
function version_info(&$irc, &$data)
|
||||
{
|
||||
|
||||
global $config;
|
||||
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);
|
||||
@@ -59,7 +53,6 @@ echo date("m-d-y H:i:s ");
|
||||
echo "VERSION\t\t". $config['version'] . "\n";
|
||||
|
||||
mysql_close();
|
||||
|
||||
}
|
||||
|
||||
###
|
||||
@@ -67,7 +60,6 @@ mysql_close();
|
||||
###
|
||||
function log_info(&$irc, &$data)
|
||||
{
|
||||
|
||||
global $config;
|
||||
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
@@ -83,17 +75,15 @@ echo date("m-d-y H:i:s ");
|
||||
echo "LOG\n";
|
||||
|
||||
mysql_close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# Get status on !down devices
|
||||
###
|
||||
function down_info(&$irc, &$data)
|
||||
{
|
||||
|
||||
global $config;
|
||||
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
@@ -108,7 +98,6 @@ mysql_close();
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "DOWN\n";
|
||||
|
||||
}
|
||||
|
||||
###
|
||||
@@ -116,10 +105,10 @@ echo "DOWN\n";
|
||||
###
|
||||
function device_info(&$irc, &$data)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$hostname = $data->messageex[1];
|
||||
|
||||
global $config;
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
@@ -136,19 +125,18 @@ mysql_close();
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "DEVICE\t\t". $device['hostname']."\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# Get status on !port <hostname port>
|
||||
###
|
||||
function port_info(&$irc, &$data)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$hostname = $data->messageex[1];
|
||||
$ifname = $data->messageex[2];
|
||||
|
||||
global $config;
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
@@ -167,18 +155,17 @@ mysql_close();
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "PORT\t\t\t" . $hostname . "\t". $ifname . "\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# !listdevices lists all devices
|
||||
###
|
||||
function list_devices(&$irc, &$data)
|
||||
{
|
||||
global $config;
|
||||
|
||||
unset ($message);
|
||||
|
||||
global $config;
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
@@ -195,56 +182,51 @@ mysql_close();
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "LISTDEVICES\n";
|
||||
|
||||
}
|
||||
|
||||
|
||||
###
|
||||
# !status <dev prt srv> gives overall status
|
||||
###
|
||||
function status_info(&$irc, &$data)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$statustype = $data->messageex[1];
|
||||
|
||||
global $config;
|
||||
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
|
||||
mysql_select_db($config['db_name']);
|
||||
|
||||
if ($statustype == "dev") {
|
||||
if ($statustype == "dev")
|
||||
{
|
||||
$devcount = array_pop(dbFetchRow("SELECT count(*) FROM devices"));
|
||||
$devup = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '1' AND `ignore` = '0'"));
|
||||
$devdown = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '0' AND `ignore` = '0'"));
|
||||
$devign = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `ignore` = '1'"));
|
||||
$devdis = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `disabled` = '1'"));
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Devices: " .$devcount . " (" .$devup . " up, " .$devdown . " down, " .$devign . " ignored, " .$devdis . " disabled" . ")"); }
|
||||
|
||||
else if ($statustype == "prt") {
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Devices: " .$devcount . " (" .$devup . " up, " .$devdown . " down, " .$devign . " ignored, " .$devdis . " disabled" . ")");
|
||||
} else if ($statustype == "prt") {
|
||||
$prtcount = array_pop(dbFetchRow("SELECT count(*) FROM ports"));
|
||||
$prtup = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'up' AND I.ignore = '0' AND I.device_id = D.device_id AND D.ignore = '0'"));
|
||||
$prtdown = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'"));
|
||||
$prtsht = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifAdminStatus = 'down' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'"));
|
||||
$prtign = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '1' OR D.ignore = '1')"));
|
||||
$prterr = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '0' OR D.ignore = '0') AND (I.ifInErrors_delta > '0' OR I.ifOutErrors_delta > '0')"));
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Ports: " .$prtcount . " (" .$prtup . " up, " .$prtdown . " down, " .$prtign . " ignored, " .$prtsht . " shutdown" . ")");}
|
||||
|
||||
else if ($statustype == "srv") {
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Ports: " .$prtcount . " (" .$prtup . " up, " .$prtdown . " down, " .$prtign . " ignored, " .$prtsht . " shutdown" . ")");
|
||||
} else if ($statustype == "srv") {
|
||||
$srvcount = array_pop(dbFetchRow("SELECT count(service_id) FROM services"));
|
||||
$srvup = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '1' AND service_ignore ='0'"));
|
||||
$srvdown = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_ignore = '0'"));
|
||||
$srvign = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_ignore = '1'"));
|
||||
$srvdis = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_disabled = '1'"));
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Services: " .$srvcount . " (" .$srvup . " up, " .$srvdown . " down, " .$srvign . " ignored, " .$srvdis . " disabled" . ")"); }
|
||||
|
||||
else {
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Services: " .$srvcount . " (" .$srvup . " up, " .$srvdown . " down, " .$srvign . " ignored, " .$srvdis . " disabled" . ")");
|
||||
} else {
|
||||
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Error: STATUS requires one of the following <dev prt srv>"); }
|
||||
|
||||
mysql_close();
|
||||
|
||||
echo date("m-d-y H:i:s ");
|
||||
echo "STATUS\t\t$statustype\n";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$bot = &new observiumbot();
|
||||
|
Reference in New Issue
Block a user