@@ -0,0 +1,190 @@
+<?php
+// Racktables inventory-system Plugin v.0.1
+// Copy this file into the plugin directory
+
+// 2012-11-08 - Carsten Schoene <cs@linux-administrator.com>
+
+// http://carsten .schoene.cc/
+
+
+# Settings
+# -----------------------------------------------------------------------------------------
+$config["inv"]["db"]['phptype'] = "mysql";
+$config["inv"]["db"]['protocol'] = "tcp";
+$config["inv"]["db"]['hostspec'] = "";
+$config["inv"]["db"]['database'] = "";
+$config["inv"]["db"]['username'] = "";
+$config["inv"]["db"]['password'] = "";
+$config["inv"]["db"]['new_link'] = true;
+$config['mdb2']['options'] = array();
+# -----------------------------------------------------------------------------------------
+
+$tab['object']['inventory'] = 'IventoryDB';
+$tabhandler['object']['inventory'] = 'InventoryTabHandler';
+require_once("MDB2.php");
+
+function InventoryTabHandler()
+{
+
+ global $config;
+
+ # Load object data
+ assertUIntArg ('object_id', __FUNCTION__);
+ $object = spotEntity ('object', $_REQUEST['object_id']);
+ $attrs = getAttrValues ($_REQUEST['object_id']);
+ $fqdn = @$attrs[3]['value'];
+ $mdbh =& MDB2::singleton($config['inv']['db'], $config['mdb2']['options'] );
+ $idsql = "SELECT inv_system_id FROM inv_system_properties WHERE
+ (datakey='get_system_hostname' AND value = '" . $object['name'] . "') OR
+ (datakey='get_system_hostname' AND value = '" . $fqdn . "') OR
+ (datakey='get_system_hostname' AND value = '" . $object['label'] . "' AND '" . $object['label'] . "' != '')
+ GROUP BY inv_system_id";
+ $idres = $mdbh->query($idsql);
+ if (PEAR::isError($idres)) {
+ echo "MDB2 idres: " . $idres->getMessage();
+ } else {
+ while (( $idrow = $idres->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ $datasql = "SELECT datakey, value FROM inv_system_properties WHERE inv_system_id = '". $idrow['inv_system_id'] . "' ORDER BY datakey";
+ $datares = $mdbh->query($datasql);
+ if (PEAR::isError($datares)) {
+ echo "MDB2 datares: " . $datares->getMessage();
+ } else {
+ echo '<table border=0 width="100%"><tr><td>';
+ htmlStyles();
+ echo '<table border="0" cellspacing="0" cellpadding="0">';
+ echo '<tr><th class="status" width=20%>Key:</th><th class="status">Value:</th></tr>';
+ $status = "statusEven";
+ while (( $row = $datares->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ echo '<tr><td class="'. $status .'" valign="top">' . $row['datakey'] . '</td><td class="'.$status.'">' . $row['value'] . '</td></tr>';
+ if ( $status == "statusEven" ) {
+ $status = "statusOdd";
+ } else {
+ $status = "statusEven";
+ }
+ }
+ echo '</table>';
+ echo '</td></tr></table>';
+ }
+ }
+ }
+ $mdbh->disconnect();
+}
+
+function htmlStyles () {
+
+ echo '
+ <script type="text/javascript">
+ function popup (url) {
+ popup = window.open(url, "Icinga", "width=1024,height=800,resizable=yes");
+ popup.focus();
+ return false;
+ }
+ </script>
+ <style type="text/css">
+ .status { font-family: arial,serif; background-color: white; color: black; }
+
+ .errorMessage { font-family: arial,serif; text-align: center; color: red; font-weight: bold; font-size: 12pt; }
+ .errorDescription { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 12pt; }
+ .warningMessage { font-family: arial,serif; text-align: center; color: red; font-weight: bold; font-size: 10pt; }
+ .infoMessage { font-family: arial,serif; text-align: center; color: red; font-weight: bold; }
+
+ .infoBox { font-family: arial,serif; font-size: 8pt; background-color: #C4C2C2; padding: 2; }
+ .infoBoxTitle { font-family: arial,serif; font-size: 10pt; font-weight: bold; }
+ .infoBoxBadProcStatus { font-family: arial,serif; color: red; }
+ A.homepageURL:Hover { font-family: arial,serif; color: red; }
+
+ .linkBox { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; padding: 1; }
+
+ .filter { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
+ .filterTitle { font-family: arial,serif; font-size: 10pt; font-weight: bold; background-color: #DBDBDB; }
+ .filterName { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
+ .filterValue { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
+
+ .itemTotalsTitle { font-family: arial,serif; font-size: 8pt; text-align: center; }
+
+ .statusTitle { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 12pt; }
+ .statusSort { font-family: arial,serif; font-size: 8pt; }
+
+ TABLE.status { font-family: arial,serif; font-size: 8pt; background-color: white; padding: 2; }
+ TH.status { font-family: arial,serif; font-size: 10pt; text-align: left; background-color: #999797; color: #DCE5C1; }
+ DIV.status { font-family: arial,serif; font-size: 10pt; text-align: center; }
+ .statusOdd { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
+ .statusEven { font-family: arial,serif; font-size: 8pt; background-color: #C4C2C2; }
+
+ .statusPENDING { font-family: arial,serif; font-size: 8pt; background-color: #ACACAC; }
+ .statusOK { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; }
+ .statusRECOVERY { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; }
+ .statusUNKNOWN { font-family: arial,serif; font-size: 8pt; background-color: #FF9900; }
+ .statusWARNING { font-family: arial,serif; font-size: 8pt; background-color: #FFFF00; }
+ .statusCRITICAL { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
+
+ .statusHOSTPENDING { font-family: arial,serif; font-size: 8pt; background-color: #ACACAC; }
+ .statusHOSTUP { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; }
+ .statusHOSTDOWN { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
+ .statusHOSTDOWNACK { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
+ .statusHOSTDOWNSCHED { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
+ .statusHOSTUNREACHABLE { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
+ .statusHOSTUNREACHABLEACK { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
+ .statusHOSTUNREACHABLESCHED { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
+
+ .statusBGUNKNOWN { font-family: arial,serif; font-size: 8pt; background-color: #FFDA9F; }
+ .statusBGUNKNOWNACK { font-family: arial,serif; font-size: 8pt; background-color: #FFDA9F; }
+ .statusBGUNKNOWNSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFDA9F; }
+ .statusBGWARNING { font-family: arial,serif; font-size: 8pt; background-color: #FEFFC1; }
+ .statusBGWARNINGACK { font-family: arial,serif; font-size: 8pt; background-color: #FEFFC1; }
+ .statusBGWARNINGSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FEFFC1; }
+ .statusBGCRITICAL { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGCRITICALACK { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGCRITICALSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGDOWN { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGDOWNACK { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGDOWNSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGUNREACHABLE { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGUNREACHABLEACK { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+ .statusBGUNREACHABLESCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
+
+ DIV.serviceTotals { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 10pt; }
+ TABLE.serviceTotals { font-family: arial,serif; font-size: 10pt; background-color: white; padding: 2; }
+ TH.serviceTotals,A.serviceTotals { font-family: arial,serif; font-size: 10pt; background-color: white; text-align: center; background-color: #999797; color: #DCE5C1; }
+ TD.serviceTotals { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #e9e9e9; }
+
+ .serviceTotalsOK { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #33FF00; }
+ .serviceTotalsWARNING { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #FFFF00; font-weight: bold; }
+ .serviceTotalsUNKNOWN { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #FF9900; font-weight: bold; }
+ .serviceTotalsCRITICAL { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #F83838; font-weight: bold; }
+ .serviceTotalsPENDING { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #ACACAC; }
+ .serviceTotalsPROBLEMS { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: orange; font-weight: bold; }
+
+
+ DIV.hostTotals { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 10pt; }
+ TABLE.hostTotals { font-family: arial,serif; font-size: 10pt; background-color: white; padding: 2; }
+ TH.hostTotals,A.hostTotals { font-family: arial,serif; font-size: 10pt; background-color: white; text-align: center; background-color: #999797; color: #DCE5C1; }
+ TD.hostTotals { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #e9e9e9; }
+
+ .hostTotalsUP { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #33FF00; }
+ .hostTotalsDOWN { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #F83838; font-weight: bold; }
+ .hostTotalsUNREACHABLE { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #F83838; font-weight: bold; }
+ .hostTotalsPENDING { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #ACACAC; }
+ .hostTotalsPROBLEMS { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: orange; font-weight: bold; }
+
+ .miniStatusPENDING { font-family: arial,serif; font-size: 8pt; background-color: #ACACAC; text-align: center; }
+ .miniStatusOK { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; text-align: center; }
+ .miniStatusUNKNOWN { font-family: arial,serif; font-size: 8pt; background-color: #FF9900; text-align: center; }
+ .miniStatusWARNING { font-family: arial,serif; font-size: 8pt; background-color: #FFFF00; text-align: center; }
+ .miniStatusCRITICAL { font-family: arial,serif; font-size: 8pt; background-color: #F83838; text-align: center; }
+
+ .miniStatusUP { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; text-align: center; }
+ .miniStatusDOWN { font-family: arial,serif; font-size: 8pt; background-color: #F83838; text-align: center; }
+ .miniStatusUNREACHABLE { font-family: arial,serif; font-size: 8pt; background-color: #F83838; text-align: center; }
+
+ .hostImportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ff0000; color: black; text-decoration: blink; }
+ .hostUnimportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ffcccc; color: black; }
+
+ .serviceImportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ff0000; color: black; text-decoration: blink; }
+ .serviceUnimportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ffcccc; color: black; }
+ </style>
+ ';
+
+}
+
+?>
|
@@ -0,0 +1,85 @@
+<?php
+/*
+// isdf - inventory system search
+// Author: Carsten Schoene
+//
+// $LastChangedDate: 2012-07-20 21:09:25 +0200 (Fr, 20. Jul 2012) $
+// $Rev: 1619 $
+*/
+
+// define our name
+define('MYNAME', "isdf-client-status");
+// open syslog connection
+openlog(MYNAME,LOG_PID | LOG_ODELAY,LOG_MAIL);
+
+// check for required extensions
+if ( ! extension_loaded("mysql") ) {
+ if ( ! dl("mysql") ) {
+ syslog(LOG_ERR,"mysql extension not loaded!");
+ exit;
+ }
+}
+
+// load additional files
+define('BASE',dirname(__FILE__));
+require_once("MDB2.php");
+require_once(BASE . "/config.inc.php");
+require_once(BASE . "/config-custom.inc.php");
+require_once(BASE . "/db.inc.php");
+
+echo '<html><head>
+<title>inventory system - client-status</title>
+</head>
+<body>
+';
+// create database connection
+$dbh =& MDB2::singleton($config['isdf']['db'], $config['mdb2']['options'] );
+
+$datasql = "SELECT inv_system_id, datakey, value FROM inv_system_properties WHERE (datakey = 'get_system_uuid' OR
+ datakey = 'get_system_default_ip' OR
+ datakey = 'get_system_hostname' OR
+ datakey = 'get_system_software' OR
+ datakey = 'get_system_date') ORDER BY inv_system_id";
+
+$idres = $dbh->query($datasql);
+if (PEAR::isError($idres)) {
+ syslog(LOG_ERR, "MDB2 idres: " . $idres->getMessage());
+} else {
+ $data = array();
+ while (( $idrow = $idres->fetchRow(MDB2_FETCHMODE_ASSOC) )) {
+ if ( $idrow['datakey'] == "get_system_software" ) {
+ // extract inventory-system
+ preg_match('/inventory-system-\d+\.\d+\.rev\d+-\d+\.\d+/', $idrow['value'],$treffer);
+ $idrow['value'] = $treffer[0];
+ } elseif ( $idrow['datakey'] == "get_system_date" ) {
+ // convert to unix timestamp
+ $idrow['value'] = strtotime($idrow['value']);
+ }
+ //array_push($data,$idrow);
+ $data[$idrow['inv_system_id']][$idrow['datakey']] = $idrow['value'];
+ }
+}
+$result = array();
+$ver = preg_replace('/-server/','',trim(exec("rpm -q inventory-system-server")));
+$lastlogin = time() - 172800;
+echo 'Server Software version: ' . $ver . ' <br/>';
+echo 'Server allowed last login: ' . $lastlogin . ' (' . date("Y-m-d H:i:s",$lastlogin) . ') <br/>';
+foreach ( $data as $idx ) {
+ if ( $idx['get_system_date'] < $lastlogin ) {
+ $idx['last_login_to_old'] = 1;
+ array_push($result, $idx);
+ continue;
+ } elseif ( trim($idx['get_system_software']) < $ver ) {
+ $idx['software_to_old'] = 1;
+ array_push($result, $idx);
+ continue;
+ }
+}
+echo '<table><tr><th>Key:</th><td>Value:</th></tr>';
+echo '</table>';
+echo '<pre>';
+print_r($result);
+echo '</pre>';
+echo '</body></html>';
+$dbh->disconnect();
+?>
|