官网对于status.dat的解释
/usr/local/nagios/var/status.dat –
This is the bread and butter file of all of the “live” information on the monitoring environment. This file gets updated every 10-20 seconds (as specified in nagios.cfg) with all current status information.
通过分析status.dat可以取也当前的服务、HOST等状态。
status.dat的大概参数如下
/usr/local/nagios/var/status.dat –
This is the bread and butter file of all of the “live” information on the monitoring environment. This file gets updated every 10-20 seconds (as specified in nagios.cfg) with all current status information.
通过分析status.dat可以取也当前的服务、HOST等状态。
status.dat的大概参数如下
- ########################################
- # NAGIOS STATUS FILE
- #
- # THIS FILE IS AUTOMATICALLY GENERATED
- # BY NAGIOS. DO NOT MODIFY THIS FILE!
- ########################################
- info {
- created=1413524014
- version=3.4.1
- last_update_check=0
- update_available=0
- last_version=3.0.1
- new_version=
- }
- programstatus {
- modified_host_attributes=0
- modified_service_attributes=0
- nagios_pid=5531
- daemon_mode=1
- ...
- }
- hoststatus {
- host_name=192.168.2.172
- modified_attributes=0
- check_command=check-host-alive
- check_period=24x7
- ...
- }
- servicestatus {
- host_name=192.168.2.172
- service_description=Current Load
- modified_attributes=0
- check_command=check_nrpe!check_load
- check_period=24x7
- ...
- }
- contactstatus {
- contact_name=kk
- modified_attributes=0
- modified_host_attributes=0
- modified_service_attributes=0
- ...
- }
- servicecomment {
- host_name=192.168.2.146
- service_description=Current Load
- entry_type=3
- comment_id=1785
- ...
- }
[code]#!/usr/bin/python
#######add by kuang at 201410 parse status.dat
################## host_status
import os
import re
filename='/usr/local/perl/status_test.dat'
filename='/usr/local/perl/status.dat'
file=open(filename,'r')
line=file.readline()
list=[]
all_line=[]
while line:
oline=line
line=file.readline()
if re.search(r'^#',oline):
continue
if oline.strip() != '':
all_line.append(oline)
file.close()
##########################
####
#### get status.dat to list
####
##########################
#print (all_line)
temp=''.join(all_line)
tmp_list=temp.split('}')
def replace_s(s):
t=re.sub(r"\s?\{","",s)
t=re.sub(r"(\t+)"," ",t)
t=re.sub(r"(\n+)","",t)
return t
tmp_list=map(replace_s,tmp_list)
for s in tmp_list:
if len(s)>0:
t=re.sub(r"\s{2,}","#",s)
# print t
tmp=t.split('#')
d={}
d1={}
info=''
for t in tmp:
if not re.search('=',t):
info=t
else:
d1[t.split('=')[0]]=t.split('=')[1]
d[info]=d1
list.append(d)
##########################
####
#### show list , list is too long
####
##########################
#print list
##########################
####
#### show status
####
##########################
#####get all ip and down status
def getpam(list,i,info,pam):
info=list[info][pam]
return info
ok=0
down=0
i=0
message=''
#dict_IP={}
list_down=[]
while i
编辑回复