使用Ruby编写nagios监控脚本监控Windows主机

发布时间:2020-06-23 15:37:06 作者:keyhappy
来源:网络 阅读:936

以下通过一个自己写的实例来说明:

监控目的是判断指定的文件是否存,如不存在就报警,而传入的参数是指定文件的根路径,也可以改成全路径,例子只是为了说明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
推荐阅读:
  1. nagios监控远端主机
  2. Nagios利用NSClient++监控Windows主机

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

主机 windows 监控

上一篇:Docker-compose使用

下一篇:BroadcastReceiver 动态注册注意事项

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》