Category Archives: MySQL

Email Server Attack

Type: Brute Force
Protocol: POP3
OS: Linux 3.6.11+ armv6l
Platform: Pi Rev. B
Memory: 512M
Daemon: Dovecot 2.1.7-7
Backend Daemon: MySQL 5.5
Backend OS: Linux 2.6.32-5-amd64
Backend Platform: Generic AMD A4-3400 APU Dual Core
Backend Memory: 3.5G
Total Attempts: 13356
Avg. Attempt/s: 2.71

Postmortem:
67.136.48.186 was *unable* to successfully authenticate to any valid user.
Attack was mitigated at the firewall (DROP).
abuse@integratelecom.com was contacted about this event.

Further Information:
Fail2ban did not detect the attack, research ongoing.
Fail2ban's ability to check logging may have been overwhelmed.
All logging is done remotely, no local logging occurs.
The RPI handled the traffic/load well, never swapped.

Log Excerpt:

Feb 22 18:14:05 hcpi004 dovecot: auth-worker(8400): sql(support,67.136.48.186): unknown user
Feb 22 18:14:12 hcpi004 dovecot: auth-worker(8400): sql(support,67.136.48.186): unknown user
Feb 22 18:14:15 hcpi004 dovecot: auth-worker(8400): sql(info,67.136.48.186): unknown user
Feb 22 18:14:15 hcpi004 dovecot: auth-worker(8400): sql(help,67.136.48.186): unknown user
Feb 22 18:14:24 hcpi004 dovecot: auth-worker(8400): sql(support,67.136.48.186): unknown user
Feb 22 18:14:26 hcpi004 dovecot: auth-worker(8400): sql(help,67.136.48.186): unknown user
Feb 22 18:14:27 hcpi004 dovecot: auth-worker(8400): sql(info,67.136.48.186): unknown user
Feb 22 18:14:28 hcpi004 dovecot: auth-worker(8400): sql(spam,67.136.48.186): unknown user
Feb 22 18:14:40 hcpi004 dovecot: auth-worker(8400): sql(administrator,67.136.48.186): unknown user
Feb 22 18:14:43 hcpi004 dovecot: auth-worker(8400): sql(support,67.136.48.186): unknown user

*SNIP*

Feb 22 19:35:23 hcpi004 dovecot: auth-worker(25283): sql(bridgette,67.136.48.186): unknown user
Feb 22 19:35:25 hcpi004 dovecot: auth-worker(25283): sql(danielle,67.136.48.186): unknown user
Feb 22 19:35:25 hcpi004 dovecot: auth-worker(25283): sql(coach,67.136.48.186): unknown user
Feb 22 19:36:39 hcpi004 dovecot: auth-worker(26746): sql(chuck,67.136.48.186): unknown user
Feb 22 19:36:43 hcpi004 dovecot: auth-worker(26746): sql(bryson,67.136.48.186): unknown user
Feb 22 19:36:45 hcpi004 dovecot: auth-worker(26746): sql(denise,67.136.48.186): unknown user
Feb 22 19:36:45 hcpi004 dovecot: auth-worker(26746): sql(dev,67.136.48.186): unknown user
Feb 22 19:36:46 hcpi004 dovecot: auth-worker(26746): sql(bridget,67.136.48.186): unknown user
Feb 22 19:36:46 hcpi004 dovecot: auth-worker(26746): sql(dominic,67.136.48.186): unknown user
Feb 22 19:36:46 hcpi004 dovecot: auth-worker(26746): sql(dakota,67.136.48.186): unknown user

irc.diff.05142011.2.txt


Index: irc.php
===================================================================
--- irc.php (revision 2317)
+++ irc.php (working copy)
@@ -1,10 +1,6 @@
#!/usr/bin/env php

-# status
-# reboot
-# log
-# help
-# down
+# port_info is broken. always reports same values no matter host selected

message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Commands: !help, !log, !status, !version, !down, !port, !device, !listdevices");
+
+echo date("m-d-y H:i:s ");
+echo "HELP\n";
+
+mysql_close();
+
+ }
+
+
+###
# Get status on !version
###
function version_info(&$irc, &$data)
@@ -40,6 +55,7 @@

$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);

+echo date("m-d-y H:i:s ");
echo "VERSION\t\t". $config['version'] . "\n";

mysql_close();
@@ -47,6 +63,31 @@
}

###
+# Get last eventlog entry
+###
+ function log_info(&$irc, &$data)
+ {
+
+global $config;
+
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);
+
+ $device = dbFetchRow("SELECT `event_id`,`host`,`datetime`,`message`,`type` FROM `eventlog` ORDER BY `event_id` DESC LIMIT 1");
+ $host=$device['host'];
+ $hostid = dbFetchRow("SELECT `hostname` FROM `devices` WHERE `device_id` = $host");
+
+$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['event_id'] ." ". $hostid['hostname'] ." ". $device['datetime'] ." ". $device['message'] ." ". $device['type']);
+
+echo date("m-d-y H:i:s ");
+echo "LOG\n";
+
+mysql_close();
+
+ }
+
+
+###
# Get status on !down devices
###
function down_info(&$irc, &$data)
@@ -56,18 +97,16 @@
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
mysql_select_db($config['db_name']);

- $query = mysql_query("SELECT * FROM `devices` where status=0");
- unset($message);
- while($device = mysql_fetch_assoc($query))
+ foreach (dbFetchRows("SELECT * FROM `devices` where status=0") as $device)
{
$message .= $sep . $device['hostname'];
$sep = ", ";
}
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
- unset($sep);

mysql_close();

+echo date("m-d-y H:i:s ");
echo "DOWN\n";

}
@@ -92,9 +131,10 @@
if ($device['ignore']) { $status = "*Ignored*"; }
if ($device['disabled']) { $status = "*Disabled*"; }

- $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
+ $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['os'] . " " . $device['version'] . " " .
$device['features'] . " " . $status);

+echo date("m-d-y H:i:s ");
echo "DEVICE\t\t". $device['hostname']."\n";

}
@@ -122,10 +162,11 @@
$pps_in = format_bi($port['ifInUcastPkts_rate']);
$pps_out = format_bi($port['ifOutUcastPkts_rate']);

- $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
+ $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
$bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");

-echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";
+echo date("m-d-y H:i:s ");
+echo "PORT\t\t\t" . $hostname . "\t". $ifname . "\n";

}

@@ -152,9 +193,58 @@
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
unset($sep);

+echo date("m-d-y H:i:s ");
echo "LISTDEVICES\n";

}
+
+
+###
+# !status gives overall status
+###
+ function status_info(&$irc, &$data)
+ {
+ $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") {
+ $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") {
+ $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") {
+ $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, "Error: STATUS requires one of the following "); }
+
+mysql_close();
+
+echo date("m-d-y H:i:s ");
+echo "STATUS\t\t$statustype\n";
+
+ }
+
}

$bot = &new observiumbot();
@@ -166,6 +256,9 @@
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!status', $bot, 'status_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!log', $bot, 'log_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!help', $bot, 'help_info');

$irc->connect($config['irc_host'], $config['irc_port']);
$irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);

irc.diff.05142011.1.txt


Index: irc.php
===================================================================
--- irc.php (revision 2317)
+++ irc.php (working copy)
@@ -1,11 +1,5 @@
#!/usr/bin/env php

-# status
-# reboot
-# log
-# help
-# down
-
message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Commands: !help, !log, !status, !version, !down, !port, !device, !listdevices");
+
+echo date("m-d-y H:i:s ");
+echo "HELP\n";
+
+mysql_close();
+
+ }
+
+
+###
# Get status on !version
###
function version_info(&$irc, &$data)
@@ -40,6 +53,7 @@

$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);

+echo date("m-d-y H:i:s ");
echo "VERSION\t\t". $config['version'] . "\n";

mysql_close();
@@ -47,6 +61,31 @@
}

###
+# Get last eventlog entry
+###
+ function log_info(&$irc, &$data)
+ {
+
+global $config;
+
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);
+
+ $device = dbFetchRow("SELECT `event_id`,`host`,`datetime`,`message`,`type` FROM `eventlog` ORDER BY `event_id` DESC LIMIT 1");
+ $host=$device['host'];
+ $hostid = dbFetchRow("SELECT `hostname` FROM `devices` WHERE `device_id` = $host");
+
+$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['event_id'] ." ". $hostid['hostname'] ." ". $device['datetime'] ." ". $device['message'] ." ". $device['type']);
+
+echo date("m-d-y H:i:s ");
+echo "LOG\n";
+
+mysql_close();
+
+ }
+
+
+###
# Get status on !down devices
###
function down_info(&$irc, &$data)
@@ -56,18 +95,16 @@
mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
mysql_select_db($config['db_name']);

- $query = mysql_query("SELECT * FROM `devices` where status=0");
- unset($message);
- while($device = mysql_fetch_assoc($query))
+ foreach (dbFetchRows("SELECT * FROM `devices` where status=0") as $device)
{
$message .= $sep . $device['hostname'];
$sep = ", ";
}
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
- unset($sep);

mysql_close();

+echo date("m-d-y H:i:s ");
echo "DOWN\n";

}
@@ -92,9 +129,10 @@
if ($device['ignore']) { $status = "*Ignored*"; }
if ($device['disabled']) { $status = "*Disabled*"; }

- $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
+ $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['os'] . " " . $device['version'] . " " .
$device['features'] . " " . $status);

+echo date("m-d-y H:i:s ");
echo "DEVICE\t\t". $device['hostname']."\n";

}
@@ -122,10 +160,11 @@
$pps_in = format_bi($port['ifInUcastPkts_rate']);
$pps_out = format_bi($port['ifOutUcastPkts_rate']);

- $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
+ $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
$bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");

-echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";
+echo date("m-d-y H:i:s ");
+echo "PORT\t\t\t" . $hostname . "\t". $ifname . "\n";

}

@@ -152,9 +191,58 @@
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
unset($sep);

+echo date("m-d-y H:i:s ");
echo "LISTDEVICES\n";

}
+
+
+###
+# !status gives overall status
+###
+ function status_info(&$irc, &$data)
+ {
+ $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") {
+ $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") {
+ $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") {
+ $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, "Error: STATUS requires one of the following "); }
+
+mysql_close();
+
+echo date("m-d-y H:i:s ");
+echo "STATUS\t\t$statustype\n";
+
+ }
+
}

$bot = &new observiumbot();
@@ -166,6 +254,9 @@
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!status', $bot, 'status_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!log', $bot, 'log_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!help', $bot, 'help_info');

$irc->connect($config['irc_host'], $config['irc_port']);
$irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);

irc.diff.05142011.txt


Index: irc.php
===================================================================
--- irc.php (revision 2284)
+++ irc.php (working copy)
@@ -1,37 +1,122 @@
#!/usr/bin/env php
+
+# status
+# reboot
+# log
+# help
+# down
+
message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);
+
+echo "VERSION\t\t". $config['version'] . "\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']);
+
+ $query = mysql_query("SELECT * FROM `devices` where status=0");
+ unset($message);
+ while($device = mysql_fetch_assoc($query))
+ {
+ $message .= $sep . $device['hostname'];
+ $sep = ", ";
+ }
+ $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
+ unset($sep);
+
+mysql_close();
+
+echo "DOWN\n";
+
+ }
+
+###
+# Get status on !device
+###
function device_info(&$irc, &$data)
{
+
$hostname = $data->messageex[1];

- $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));
+global $config;
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);

+ $device = dbFetchRow("SELECT * FROM `devices` WHERE `hostname` = ?",array($hostname));
+
+mysql_close();
+
if ($device['status'] == 1) { $status = "Up " . formatUptime($device['uptime'] . " "); } else { $status = "Down "; }
if ($device['ignore']) { $status = "*Ignored*"; }
if ($device['disabled']) { $status = "*Disabled*"; }

$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .
$device['features'] . " " . $status);
+
+echo "DEVICE\t\t". $device['hostname']."\n";
+
}

+
+###
+# Get status on !port
+###
function port_info(&$irc, &$data)
{
$hostname = $data->messageex[1];
$ifname = $data->messageex[2];

- $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));
- $port = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `ifName` = '".mres($ifname)."' OR `ifDescr` = '".mres($ifname)."' AND device_id = '".$device['device_id']."'"));
+global $config;
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);

+ $device = dbFetchRow("SELECT * FROM `devices` WHERE `hostname` = ?",array($device));
+ $port = dbFetchRow("SELECT * FROM `ports` WHERE `ifName` = ? OR `ifDescr` = ? AND device_id = ?", array($ifname, $ifname, $device['device_id']));
+
+mysql_close();
+
$bps_in = formatRates($port['ifInOctets_rate']);
$bps_out = formatRates($port['ifOutOctets_rate']);
$pps_in = format_bi($port['ifInUcastPkts_rate']);
@@ -39,19 +124,36 @@

$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .
$bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");
+
+echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";
+
}

+
+###
+# !listdevices lists all devices
+###
function list_devices(&$irc, &$data)
{
- $query = mysql_query("SELECT * FROM `devices`");
- unset($message);
- while($device = mysql_fetch_assoc($query))
+ unset ($message);
+
+global $config;
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);
+mysql_select_db($config['db_name']);
+
+ foreach (dbFetchRows("SELECT `hostname` FROM `devices`") as $device)
{
$message .= $sep . $device['hostname'];
$sep = ", ";
}
+
+mysql_close();
+
$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);
unset($sep);
+
+echo "LISTDEVICES\n";
+
}
}

@@ -62,6 +164,8 @@
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!listdevices', $bot, 'list_devices');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info');
$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');

$irc->connect($config['irc_host'], $config['irc_port']);
$irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);