ASNMTAP
view release on metacpan or search on metacpan
applications/htmlroot/snmptraps/include/classes/class.mysqlDB.php view on Meta::CPAN
<?
#########################################################
# SNMPTraps-Frontend for Nagios & ASNMTAP #
# #
# by Michael Lübben #
# --- Lizenz GPL --- #
#########################################################
/**
* This Class handles database-connection and - queries
*/
class database {
/**
* Constructor
*
* @param config $configINI
*
* @author Michael Luebben <michael_luebben@web.de>
*/
function database(&$configINI) {
$this->configINI = &$configINI;
}
/**
* Make a connection to the database
*
* @param array $configINI
*
* @author Michael Luebben <michael_luebben@web.de>
*/
function connect() {
global $configINI, $FRONTEND;
$connect = @mysql_pconnect($configINI['database']['host'], $configINI['database']['user'], $configINI['database']['password']);
$dbSelect['code'] = @mysql_select_db($configINI['database']['name'], $connect);
// On error, create a array entry with the mysql error
if(!$dbSelect['code']) {
$FRONTEND->printError("DBCONNECTION",mysql_error());
$FRONTEND->closeSite();
$FRONTEND->printSite();
exit;
}
return($dbSelect);
}
/**
* Read Traps from database
*
* @param string $sort
* @param boolean $limit
* @param array $table
*
* @author Michael Luebben <michael_luebben@web.de>
*/
function readTraps($limit) {
global $table, $FRONTEND;
/**
* @author Alex Peeters [alex.peeters@citap.be]
*/
// Create WHERE clausel
if($_REQUEST['severity'] == "" and $_REQUEST['hostname'] == "" and $_REQUEST['trapOID'] == "" and $_REQUEST['category'] == "") {
$dbQuery = '';
} elseif ($_REQUEST['severity'] == "UNKNOWN" and $_REQUEST['hostname'] == "" and $_REQUEST['trapOID'] == "") {
$dbQuery = '';
} else {
if($_REQUEST['severity'] != "UNKNOWN") {
if ($_REQUEST['severity'] != "") {
if ($_REQUEST['severity'] == "OK") {
$dbQuerySet[] = "(severity = 'Normal' or severity = 'INFORMATIONAL')";
}elseif ($_REQUEST['severity'] == "WARNING") {
$dbQuerySet[] = "(severity = 'MINOR' or severity = 'WARNING')";
}elseif ($_REQUEST['severity'] == "CRITICAL") {
$dbQuerySet[] = "(severity = 'CRITICAL' or severity = 'MAJOR' or severity = 'SEVERE')";
}
}
if ($_REQUEST['category'] != "") {
$dbQuerySet[] = "category = '".rawurldecode($_REQUEST['category'])."'";
}
}
if ($_REQUEST['hostname'] != "") {
$a = 0;
$hostnames = split ( '\,', $_REQUEST['hostname'] );
foreach ( $hostnames as $hostname ) {
if ($_REQUEST['FQDN'] == "T") {
$hostnames[$a++] = "hostname = '$hostname'";
} else {
$hostnames[$a++] = "hostname like '$hostname.%'";
}
}
$dbQuerySet[] = '('. join (' or ', $hostnames ) .')';
}
if ($_REQUEST['trapOID'] != "") {
$teller = 0;
$trapOIDsString = split ('\|', $_REQUEST['trapOID']);
( run in 0.899 second using v1.01-cache-2.11-cpan-d8267643d1d )