python3帮助类,用于插件开发和nagios管理。

python-nagios-helpers3的Python项目详细描述


python nagios helpers a.k.anaghelp是用于构建nagiosactive插件的类集合。 强烈建议使用python-textops 操作收集的数据。

下面是一个活动python插件的示例,创建一个文件linux_fsfull.py:

from naghelp import *
from textops import *

class LinuxFsFull(ActivePlugin):
    """ Basic plugin to monitor full filesystems on Linux systems"""
    cmd_params = 'user,passwd'
    tcp_ports = '22'

    def collect_data(self,data):
        data.df = Ssh(self.host.ip,self.host.user,self.host.passwd).run('df -h')

    def parse_data(self,data):
        df = data.df.skip(1)
        data.fs_critical = df.greaterequal(98,key=cuts(r'(\d+)%')).cut(col='5,4').renderitems()
        data.fs_warning = df.inrange(95,98,key=cuts(r'(\d+)%')).cut(col='5,4').renderitems()
        data.fs_ok = df.lessthan(95,key=cuts(r'(\d+)%')).cut(col='5,4').renderitems()

    def build_response(self,data):
        self.response.add_list(CRITICAL,data.fs_critical)
        self.response.add_list(WARNING,data.fs_warning)
        self.response.add_list(OK,data.fs_ok)

if __name__ == '__main__':
   LinuxFsFull().run()

手动执行:

python linux_fsfull.py --ip=127.0.0.1 --user=naghelp --passwd=lgpl

如果出错,它可能会返回如下信息:

STATUS : CRITICAL:2, WARNING:1, OK:3
==================================[  STATUS  ]==================================

----( CRITICAL )----------------------------------------------------------------
/ : 98%
/home : 99%

----( WARNING )-----------------------------------------------------------------
/run/shm : 95%

----( OK )----------------------------------------------------------------------
/dev : 1%
/run : 1%
/run/lock : 0%


============================[ Plugin Informations ]=============================
Plugin name : __main__.LinuxFsFull
Description : Basic plugin to monitor full filesystems on Linux systems
Ports used : tcp = 22, udp = none
Execution time : 0:00:00.673851
Exit code : 2 (CRITICAL), __sublevel__=0

或者如果没有错误:

OK

============================[ Plugin Informations ]=============================
Plugin name : __main__.LinuxFsFull
Description : Basic plugin to monitor full filesystems on Linux systems
Ports used : tcp = 22, udp = none
Execution time : 0:00:00.845603
Exit code : 0 (OK), __sublevel__=0

naghelp将自动管理一些选项:

$ python linux_fsfull.py -h
Usage:
linux_fsfull.py [options]

Options:
  -h, --help         show this help message and exit
  -v                 Verbose : display informational messages
  -d                 Debug : display debug messages
  -l FILE            Redirect logs into a file
  -i                 Display plugin description
  -n                 Must be used when the plugin is started by nagios
  -s                 Save collected data in a temporary file
  -r                 Use saved collected data (option -s)
  -a                 Collect data only and print them
  -b                 Collect and parse data only and print them

  Host attributes:
    To be used to force host attributes values

    --passwd=PASSWD  Passwd
    --ip=IP          Host IP address
    --user=USER      User
    --name=NAME      Hostname

更多信息,Read The Fabulous Manual

新闻

0.3.0(2018-8-28)

  • python nagios助手从python2到python 3的端口

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java刷新系统。用自己的记录器输出   使用Jython将参数从Java传递到Python   JavaSocksV4代理   java如何使用通知?   java@DirtiesConext不工作   java将多个jar组合成一个(使用maven)   java使用相等运算符比较两个类   java我怎样才能让两个JOptionPane一起出现在我的第一页上,并让它们在两个页面上都有正确的答案?   html无法访问java中资产文件夹内的文件   通过post命令向SpringWebApp发送对象时,java对象字段为null   单个实例中静态变量的类更改值(Java)   java解决方案是什么   试图检查网站所有受支持的密码套件的安全性,在java中遇到chacha20和poly1035问题