插件开发和nagios管理的辅助类。
项目描述
python-nagios-helpers,又名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.2.3 (2018-06-20)
修复collect.Snmp的priv_protocol参数
0.2.2 (2018-02-28)
在Snmp类中添加object_identity_to_string选项,在Snmp.*walk方法中添加ignore_errors选项,添加SnmpWalkError异常以获取截断的结果
0.2.1 (2018-02-01)
更新Winrm收集类
0.2.0 (2018-02-01)
添加Winrm收集类
0.1.23 (2017-09-08)
将save_host_data()移动到plugin run()方法中
0.1.22 (2017-07-07)
添加Ssh run_script()、get()和put()方法
0.1.21 (2017-04-26)
添加textops.logger作为管理日志记录器
0.1.20 (2017-04-26)
将主机调试跟踪移动到load_host_data()
0.1.19 (2017-04-22)
在find_plugins()中缓存发现的插件
0.1.18 (2017-04-07)
在Http()类中添加post和session处理
0.1.17 (2017-04-05)
不要多次添加日志记录器处理程序
0.1.16 (2017-03-27)
现在可以以额外的选项实例化插件
0.1.15 (2017-03-20)
修复了插件没有docstring的情况
0.1.14 (2017-01-31)
在setup.py中移除对sphinx包的版本限制
0.1.12 (2017-01-26)
删除无用的代码
0.1.11 (2017-01-26)
runsh*现在返回用于textops操作的扩展类型
0.1.10 (2016-09-05)
添加collect_*选项,为collect_data()添加超时
0.1.9 (2016-08-26)
将主机对象中的所有选项映射(不仅仅是host__*)
0.1.8 (2016-08-04)
插件输出的性能数据现在以空格分隔
0.1.7 (2016-04-14)
在插件信息部分添加活动插件的执行日期,为受管理的主机添加更新日期
0.1.6 (2016-04-12)
添加HostsManager混入,添加collect.Http类,创建Lockfile工具,将Timeout工具移至tools.py
0.1.5 (2016-03-23)
添加Gauges混入,添加文档,许多其他改进
0.1.4 (2016-03-08)
更好的错误管理
0.1.3 (2016-01-13)
添加文档
0.1.1 (2016-01-08)
添加启动器
0.1.0 (2015-12-17)
添加一些文档、测试,调整一些函数
0.0.7 (2015-11-19)
第一个工作版本
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码分发
构建分发
散列 for python_nagios_helpers-0.2.3-py2-none-any.whl
算法 | 散列摘要 | |
---|---|---|
SHA256 | cf0d3c5c0b0aceab353efb8b1cdb0e52f5c00a8b43969e992419ccaa6e772743 |
|
MD5 | 1e6982f5a64a5c7de8a64555d78702c7 |
|
BLAKE2b-256 | ced1585798eace087431489e8c6cb22e8b2900897ed77c6c9461a376993e9412 |