您好,登錄后才能下訂單哦!
以下通過(guò)一個(gè)自己寫(xiě)的實(shí)例來(lái)說(shuō)明:
監(jiān)控目的是判斷指定的文件是否存,如不存在就報(bào)警,而傳入的參數(shù)是指定文件的根路徑,也可以改成全路徑,例子只是為了說(shuō)明ruby腳本在nagios中的部署方法,而并不是為了說(shuō)明使用ruby來(lái)判斷文件是否存在有多便利。
#!/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=""
#讀取參數(shù)
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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。