<?php
require_once(dirname(__FILE__) . '/../componenthelper.inc.php');
nagiosxicustomendpoints_component_init();
function nagiosxicustomendpoints_component_init()
{
$args = array(
COMPONENT_NAME => "nagiosxicustomendpoints",
COMPONENT_VERSION => "1.0",
COMPONENT_AUTHOR => "Nagios Enterprises, LLC",
COMPONENT_DESCRIPTION => "Demonstrate Nagios XI Custom API Endpoints",
COMPONENT_TITLE => "Nagios XI Custom API Endpoints Example"
);
register_component("nagiosxicustomendpoints", $args);
register_custom_api_callback('com', 'mangosis', 'nagiosxicustomendpoints_awesome_example');
}
function nagiosxicustomendpoints_awesome_example($endpoint, $verb,$args) {
$xml = '';
foreach ($args as $key => $arg) {
$cpu = shell_exec("/usr/local/nagios/libexec/check_nrpe -H ".$arg." -t 30 -c check_cpu_stats -a '-w 85 -c 95'");
$ram = shell_exec("/usr/local/nagios/libexec/check_nrpe -H ".$arg." -t 30 -c check_mem -a '-w 20 -c 10'");
$disk = shell_exec("/usr/local/nagios/libexec/check_nrpe -H ".$arg." -t 30 -c check_disk -a '-w 5 -c 10'");
}
$xml = " <xml>
<cpu>$cpu</cpu>
<ram>$ram</ram>
<disk>$disk</disk>
<endpoint>$endpoint</endpoint>
<verb>$verb</verb>
<arg>$arg</arg>
</xml>";
return xml2json::transformXmlStringToJson($xml);
}
?>
附上个人脚本
#!/bin/bash
#
DEV=`df -hP | grep '^/dev/*' | cut -d' ' -f1 | sort`
for I in $DEV
do dev=`df -Ph | grep $I | awk '{print $1}'`
size=`df -Ph | grep $I | awk '{print $2}'`
used=`df -Ph | grep $I | awk '{print $3}'`
free=`df -Ph | grep $I | awk '{print $4}'`
rate=`df -Ph | grep $I | awk '{print $5}'`
echo -e "$I:\tsize:$size\tused:$used\tfree:$free\trate:$rate"
F=`echo $rate | awk -F% '{print $1}'`
done
#!/bin/bash
#
CPU1=`cat /proc/stat | grep 'cpu ' | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}'`
sleep 1
CPU2=`cat /proc/stat | grep 'cpu ' | awk '{print $2" "$3" "$4" "$5" "$6" "$7" "$8}'`
IDLE1=`echo $CPU1 | awk '{print $4}'`
IDLE2=`echo $CPU2 | awk '{print $4}'`
CPU1_TOTAL=`echo $CPU1 | awk '{print $1+$2+$3+$4+$5+$6+$7}'`
CPU2_TOTAL=`echo $CPU2 | awk '{print $1+$2+$3+$4+$5+$6+$7}'`
IDLE=`echo "$IDLE2-$IDLE1" | bc`
CPU_TOTAL=`echo "$CPU2_TOTAL-$CPU1_TOTAL" | bc`
RATE=`echo "scale=4;($CPU_TOTAL-$IDLE)/$CPU_TOTAL*100" | bc | awk '{printf "%.2f",$1}'`
echo "${RATE}%"
#!/bin/bash
#
total=$(free -m | sed -n '2p' | awk '{print $2}')
used=$(free -m | sed -n '2p' | awk '{print $3}')
free=$(free -m | sed -n '2p' | awk '{print $4}')
shared=$(free -m | sed -n '2p' | awk '{print $5}')
buff=$(free -m | sed -n '2p' | awk '{print $6}')
cached=$(free -m | sed -n '2p' | awk '{print $7}')
rate=`echo "scale=2;$used/$total" | bc | awk -F. '{print $2}'`
echo -e "${rate}%