Python3插件开发和管理辅助类。
项目描述
python-nagios-helpers A.K.A naghelp 是用于构建nagios Active 插件的类集合。强烈建议使用 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
更多信息,请阅读精彩手册!
新闻
0.3.0 (2018-8-28)
将python-nagios-helpers从python2迁移到python3
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定要选择哪个,请了解有关 安装包 的更多信息。
源分布
python-nagios-helpers3-0.2.2.tar.gz (68.4 kB 查看哈希)
关闭
python-nagios-helpers3-0.2.2.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 6b47604fe573e53a77293b8bd50307f1d48c90e8dcc5a2e1858164775949cdce |
|
MD5 | 4f5b264d1c5559843fd6314de5786787 |
|
BLAKE2b-256 | 355cc25f1a9809efb691b8cb02333638ed8de97276b881e2452ae8f985ab0e06 |