使用Ruby编写nagios监控脚本监控Windows主机
以下通过一个自己写的实例来说明:
监控目的是判断指定的文件是否存,如不存在就报警,而传入的参数是指定文件的根路径,也可以改成全路径,例子只是为了说明ruby脚本在nagios中的部署方法,而并不是为了说明使用ruby来判断文件是否存在有多便利。
#!/usr/bin/env ruby
# To use in nagios for NSClient++:
# - Put the script into the %SCRIPT% directory
# modifications in NSC.ini:
# =========================
#
# in [modules]:
# CheckExternalScripts.dll
#
# in [NRPE]:
# allow_arguments=1
# allow_nasty_meta_chars=1
# allowed_hosts=x.x.x.x
#
# in [External Script]:
# allow_arguments=1
# allow_nasty_meta_chars=1
#
# in [Script Wrappings]:
# rb=ruby.exe scripts\%SCRIPT% %ARGS%
#
# in [Wrapped Scripts]:
# check_sftpDayfile=check_sftpDayfile.rb $ARG1$
#
#
# nagios usage:
# =============
#
# define service{
# use generic-service
# host_name windowsxx
# service_description SFtp Dayfile
# check_command check_nrpe!check_sftpDayfile!"d:/path"
# }
def fu(ss)
mm=ss.to_s
if ss<10 then
mm="0"+ss.to_s;
end
return mm
end
rootpath=""
#读取参数
if ARGV[0] then
rootpath=ARGV[0];
end
d=Time.now.day
m=Time.now.mon
y=Time.now.year.to_s
fullpath=rootpath+y+"_"+fu(m)+"_"+fu(d)+"/test.txt"
#p fullpath
if File.exist?(fullpath) then
print "Ok,"+fullpath+" File exist!";exit 0;
else
print "Error,"+fullpath+" File no exits!!";exit 2;
end
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。