溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用Ruby編寫nagios監控腳本監控Windows主機

發布時間:2020-06-23 15:37:06 來源:網絡 閱讀:952 作者:keyhappy 欄目:移動開發

以下通過一個自己寫的實例來說明:

監控目的是判斷指定的文件是否存,如不存在就報警,而傳入的參數是指定文件的根路徑,也可以改成全路徑,例子只是為了說明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
 

附件:http://down.51cto.com/data/2360840
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女