惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

博客园 - 菲一打

【转】Linux从入门到精通——运维工程师成长路线图——CTO马哥Linux视频教学 【转】 要做linux运维工程师的朋友,必须要掌握以下几个工具才行 【转】Linux shell笔记 【转】Linux上vi(vim)编辑器使用教程 无法远程连接SQLSERVER2000的解决方法 Python类的__getitem__和__setitem__特殊方法 让Python支持中文注释 【转】python入门指引 【转】布同:如何循序渐进学习Python语言 在nagios中监控windows主机系统地址的状态 nagios中监测dns 227.7.128.68的网络状态 【转】新手该如何学python怎么学好python? 【转】手游公司运维之从一个人运维到运维主管 【转】VMware 克隆 Linux 系统后找不到 eth0 网卡问题 【转】sed & awk常用正则表达式 【转】Linux 服务器安全配置 【转】shell脚本实现多台服务器自动巡检--可参考学习 【转】nagios 命令解释 在nagios中使用nrpe自定义脚本
在nagios中使用python脚本监控linux主机
菲一打 · 2014-04-17 · via 博客园 - 菲一打

在被监控端192.168.5.110
1.先把getload.py放到/usr/local/nagios/libexec内
[root@nhserver1 ~]# vim /usr/local/nagios/libexec/getload.py
#! /usr/bin/env python
import os,sys
(d1,d2,d3) = os.getloadavg()
if d1 >= 5.0:
        print "GETLOADAVG CRITICAL: Load average is %.2f" % (d1)
        sys.exit(2)
elif d1 >= 2.0:
        print "GETLOADAVG WARNING: Load average is %.2f" %(d1)
else:
        print "GETLOADAVG OK: Load average is %.2f" %(d1)

[root@nhserver1 libexec]# chmod a+x getload.py
[root@nhserver1 libexec]# chown nagios:nagios getload.py

2. 在nrpe内加入自定义的命令
[root@nhserver1 libexec]# vim /usr/local/nagios/etc/nrpe.cfg
 command[nh_check_getload]=/usr/local/nagios/libexec/getload.py

------------------------------------------------------------------------------------------

在nagios服务端测试192.168.5.10

[root@nhserver2 libexec]# /usr/local/nagios/libexec/check_nrpe -H 192.168.5.110 -c nh_check_getload
GETLOADAVG OK: Load average is 0.06

在服务端测试192.168.5.10的nagios中加入自定义脚本
[root@nhserver2 ~]# cd /usr/local/nagios/etc/objects
[root@nhserver2 objects]# vim hosts_192.168.5.110.cfg
define host{
        use                     linux-server
        host_name               192.168.5.110
        alias                   192.168.5.110
        address                 192.168.5.110
        }

define hostgroup{
        hostgroup_name          nh_linuxs
        alias                   nh_linuxs
        members                 192.168.5.110
        }

define service{
        use                     local-service
        host_name               192.168.5.110
        service_description     check-host-alive
        check_command           check-host-alive
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
     }

define service{
        use                     local-service
        host_name               192.168.5.110
        service_description     SSH
        check_command           check_ssh
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        }

define service{
        use                     local-service
        host_name               192.168.5.110
        service_description     check_nrpe_check_users
        check_command           check_nrpe!nh_check_users
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        }
define service{
        use                     local-service
        host_name               192.168.5.110
        service_description     check_nrpe_check_getload
        check_command           check_nrpe!nh_check_getload
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        }

[root@nhserver2 objects]# service nagios reload

在nagios的services中就可看到的状态了
192.168.5.110
check_nrpe_check_getload    
    OK     04-17-2014 16:21:53     0d 0h 4m 22s     1/5     GETLOADAVG OK: Load average is 0.00