又一个关于nagios联系人的接口脚本
时间:2008-08-16 来源:jordanfang
#!/bin/sh
CACHE_FILE=/usr/local/nagios/var/objects.cache
CONTACT_GROUP_FILE=/tmp/object_contactgroup_tmp_file
HOST_FILE=/tmp/object_host_tmp_file
SERVICE_FILE=/tmp/object_service_tmp_file
check_host() {
if grep -q "\<$contact_group\>" $HOST_FILE
then
host=`grep -B4 "\<$contact_group\>" $HOST_FILE | grep host_name | awk '{print "<tr><td>"$2"</td></tr>"}'`
echo -e "$host"
fi
}
check_service() {
for hosts in `grep -B5 "\<$contact_group\>" $SERVICE_FILE | grep host_name |awk '{print $2}' | sort | uniq`
do
echo -e "<tr><td>$hosts</td>"
grep -B5 $contact_group $SERVICE_FILE |grep -A1 $hosts$ | grep service_description | awk '{print "<td>"$2"</td>"}'
echo -e "</tr>"
done
}
person=$1
grep -A4 "define contactgroup {" $CACHE_FILE >$CONTACT_GROUP_FILE
grep -A6 "define host {" $CACHE_FILE >$HOST_FILE
grep -A5 "define service {" $CACHE_FILE >$SERVICE_FILE
if grep -q "${person}_level" $CONTACT_GROUP_FILE
then
echo -e "报警发给${person}节点有:"
echo "<table id='table' cellspacing='0' cellpadding='0' border='1'>"
for contact_group in `grep -B2 "${person}_level" $CONTACT_GROUP_FILE |grep contactgroup_name | grep -v charge | awk '{print $2}'`
do
check_host
done
echo "</table>"
echo -e "报警发给${person}服务有:"
echo "<table id='table' cellspacing='0' cellpadding='0' border='1'>"
for contact_group in `grep -B2 "${person}_level" $CONTACT_GROUP_FILE |grep contactgroup_name | grep -v charge | awk '{print $2}'`
do
check_service
done
echo "</table>"
else
echo "<div>you input the wrong person,please check</div>"
exit 1
fi
CACHE_FILE=/usr/local/nagios/var/objects.cache
CONTACT_GROUP_FILE=/tmp/object_contactgroup_tmp_file
HOST_FILE=/tmp/object_host_tmp_file
SERVICE_FILE=/tmp/object_service_tmp_file
check_host() {
if grep -q "\<$contact_group\>" $HOST_FILE
then
host=`grep -B4 "\<$contact_group\>" $HOST_FILE | grep host_name | awk '{print "<tr><td>"$2"</td></tr>"}'`
echo -e "$host"
fi
}
check_service() {
for hosts in `grep -B5 "\<$contact_group\>" $SERVICE_FILE | grep host_name |awk '{print $2}' | sort | uniq`
do
echo -e "<tr><td>$hosts</td>"
grep -B5 $contact_group $SERVICE_FILE |grep -A1 $hosts$ | grep service_description | awk '{print "<td>"$2"</td>"}'
echo -e "</tr>"
done
}
person=$1
grep -A4 "define contactgroup {" $CACHE_FILE >$CONTACT_GROUP_FILE
grep -A6 "define host {" $CACHE_FILE >$HOST_FILE
grep -A5 "define service {" $CACHE_FILE >$SERVICE_FILE
if grep -q "${person}_level" $CONTACT_GROUP_FILE
then
echo -e "报警发给${person}节点有:"
echo "<table id='table' cellspacing='0' cellpadding='0' border='1'>"
for contact_group in `grep -B2 "${person}_level" $CONTACT_GROUP_FILE |grep contactgroup_name | grep -v charge | awk '{print $2}'`
do
check_host
done
echo "</table>"
echo -e "报警发给${person}服务有:"
echo "<table id='table' cellspacing='0' cellpadding='0' border='1'>"
for contact_group in `grep -B2 "${person}_level" $CONTACT_GROUP_FILE |grep contactgroup_name | grep -v charge | awk '{print $2}'`
do
check_service
done
echo "</table>"
else
echo "<div>you input the wrong person,please check</div>"
exit 1
fi
相关阅读 更多 +