Here a little script to display Infos from GLPI in Nagios / Icinga / ... including links to URLs like docu, ssh, splunk or whatever you defin as an Document connected to this device.
First we define a new view in our GLPI database ...
create or replace view v_docu as
select
j.id as itemid,
a.id as documents_id ,
a.name as documents_name ,
CASE WHEN a.filepath is not null THEN CONCAT('https://glpi-server.yourdomain.com/glpi/front/document.send.php?docid=',a.id)
WHEN a.link is not null THEN a.link
ELSE NULL
END as documents_link
FROM
glpi_documents a,
glpi_documents_items b,
glpi_infocoms j
WHERE
b.documents_id=a.id and
b.itemtype='Computer' and
b.items_id=j.items_id and
j.itemtype='Computer' and
( a.link is not null or a.filepath is not null )
UNION
select
j.id as itemid,
a.id as documents_id ,
a.name as documents_name ,
CASE WHEN a.filepath is not null THEN CONCAT('https://glpi-server.yourdomain.com/glpi/front/document.send.php?docid=',a.id)
WHEN a.link is not null THEN a.link
ELSE NULL
END as documents_link
FROM
glpi_documents a,
glpi_documents_items b,
glpi_infocoms j
WHERE
b.documents_id=a.id and
b.itemtype='NetworkEquipment' and
b.items_id=j.items_id and
j.itemtype='NetworkEquipment' and
( a.link is not null or a.filepath is not null )
UNION
select
j.id as itemid,
a.id as documents_id ,
a.name as documents_name ,
CASE WHEN a.filepath is not null THEN CONCAT('https://glpi-server.yourdomain.com/glpi/front/document.send.php?docid=',a.id)
WHEN a.link is not null THEN a.link
ELSE NULL
END as documents_link
FROM
glpi_documents a,
glpi_documents_items b,
glpi_infocoms j
WHERE
b.documents_id=a.id and
b.itemtype='PluginAppliancesAppliance' and
b.items_id=j.items_id and
j.itemtype='PluginAppliancesAppliance' and
( a.link is not null or a.filepath is not null );
then we create the php program check_glpi_info
#!/usr/bin/php
<?php
function docu ($arg_1,$arg_2) {
//mysql informations
$server = "10.11.12.13";
$user = "glpi";
$pw = "type_your_glpi_password_here";
$db = "glpi";
$link = mysql_connect($server,$user,$pw);
if (!$link) {
die('Connection failed: ' . mysql_error());
}
# select
mysql_select_db($db, $link) or die('Could not select database.');
$query = "SELECT documents_name,documents_link FROM v_docu WHERE itemid=".$arg_1." Order By documents_name DESC LIMIT 0,10" ;
$result = mysql_query($query) ;
if (!$result) {
die('Query 1 failed: ' . mysql_error());
}
while ($row = mysql_fetch_array($result))
{
$URL = str_replace('HOSTNAME', $arg_2 , $row['documents_link']);
print "<span style='color:blue'>Link: <a href=${URL} target=_blank > ${row['documents_name']}</a> \n";
}
}
function cluster ($arg_1) {
//mysql informations
$server = "10.11.12.13";
$user = "glpi";
$pw = "type_your_glpi_password_here";
$db = "glpi";
$link = mysql_connect($server,$user,$pw);
if (!$link) {
die('Connection failed: ' . mysql_error());
}
# select
mysql_select_db($db, $link) or die('Could not select database.');
$query = "select CLUSTERNAME from v_cluster_link where CLUSTERMEMBER='".$arg_1."'" ;
$result = mysql_query($query) ;
if (!$result) {
die('Query 1 failed: ' . mysql_error());
}
while ($row = mysql_fetch_array($result))
{
print "<span style='color:blue'>Member of Cluster: <a href=http://icinga.yourdomain.com/icinga/cgi-bin/status.cgi?host=${row['CLUSTERNAME']} target=_blank > ${row['CLUSTERNAME']}</a>\n";
}
}
// Report all errors except E_NOTICE
error_reporting(E_ALL ^ E_NOTICE);
// e.g. glpi-info.php?host=server-name.domain.com
// $host = $_GET['host'];
$fqdn = strtolower($argv[1]);
if($argv[2]!=""){
$cname = strtolower($argv[2]);
}
sleep(rand(0, 4));
$server = "10.11.12.13";
$user = "glpi";
$pw = "type_your_glpi_password_here";
$db = "glpi";
// and action
if($fqdn!=""){
$link = mysql_connect($server,$user,$pw);
if (!$link) {
die('Connection failed: ' . mysql_error());
}
mysql_select_db($db, $link) or die('Could not select database.');
sleep(rand(0, 5));
$query = "SELECT itemid,type,subtype,user,site,location,os,serial,inventorynumber,manufactur,model,fqdn,name FROM v_info WHERE LOWER(fqdn)='".$fqdn."' LIMIT 1";
#$result = mysql_query($query) or die("Query failed");
$result = mysql_query($query) ;
if (!$result) {
die('Query 1 failed: ' . mysql_error());
}
$result = mysql_fetch_assoc($result);
if($result['itemid'] != ""){
print "Info from GLPI for System : {$result['fqdn']} \n";
print "Manufacture / Model : {$result['manufactur']} / {$result['model']} \n";
print "Responsible Technician: {$result['user']} \n";
print "OS: {$result['os']} \n";
print "Site / Location: {$result['site']} / {$result['location']} \n";
print "Type: {$result['type']} , {$result['subtype']} \n";
print "Serial / InventoryNR: {$result['serial']} / {$result['inventorynumber']} \n";
mysql_close($link);
cluster($result['name']);
docu($result['itemid'],$result['fqdn']);
exit(0);
}
$name_array=preg_split('/\./', $fqdn );
$host=$name_array[0];
#print_r($name_array);
#print_r($fqdn);
#$link = mysql_connect($server,$user,$pw) or die("Connection failed");
# mysql_select_db($db, $link) or die('Could not select database.');
sleep(rand(0, 5));
$query = "SELECT itemid,type,subtype,user,site,location,os,serial,inventorynumber,manufactur,model,name FROM v_info WHERE LOWER(name)='".$host."' LIMIT 1";
#print_r($result);
$result = mysql_query($query);
if (!$result) {
die('Query 2 failed: ' . mysql_error());
}
$result = mysql_fetch_assoc($result);
if($result['itemid'] != ""){
print "Info from GLPI for System : {$result['name']} \n";
print "Manufacture / Model : {$result['manufactur']} / {$result['model']} \n";
print "Responsible Technician: {$result['user']} \n";
print "OS: {$result['os']} \n";
print "Site / Location: {$result['site']} / {$result['location']} \n";
print "Type: {$result['type']} , {$result['subtype']} \n";
print "Serial / InventoryNR: {$result['serial']} / {$result['inventorynumber']} \n";
mysql_close($link);
cluster($result['name']);
docu($result['itemid'],$result['name']);
exit(0);
}
if($cname!="$"){
#$link = mysql_connect($server,$user,$pw) or die("Connection failed");
#mysql_select_db($db, $link) or die('Could not select database.');
$query = "SELECT itemid,type,subtype,user,site,location,os,serial,inventorynumber,manufactur,model,fqdn,name FROM v_info WHERE LOWER(name)='".$cname."' LIMIT 1";
$result = mysql_query($query);
if (!$result) {
die('Query 3 failed: ' . mysql_error());
}
$result = mysql_fetch_assoc($result);
if($result['itemid'] != ""){
print "Info from GLPI for System : $cname {$result['fqdn']} \n";
print "Manufacture / Model : {$result['manufactur']} / {$result['model']} \n";
print "Responsible Technician: {$result['user']} \n";
print "OS: {$result['os']} \n";
print "Site / Location: {$result['site']} / {$result['location']} \n";
print "Type: {$result['type']} , {$result['subtype']} \n";
print "Serial / InventoryNR: {$result['serial']} / {$result['inventorynumber']} \n";
mysql_close($link);
cluster($result['name']);
docu($result['itemid'],$result['fqdn']);
exit(0);
}
}
print "$fqdn or $host not found\n";
mysql_close($link);
exit(3);
#exit(0);
}
?>