以下通過一個自己寫的實例來說明:
監控目的是判斷指定的文件是否存,如不存在就報警,而傳入的參數是指定文件的根路徑,也可以改成全路徑,例子只是為了說明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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。