Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。
Nagios是调用微信公共平台的api接口发送报警邮件。在正式操作之前,有几个准备工作要做。先安装nagios,可以使用我提供的nagios一键安装脚本。然后是去微信公共平台申请一个企业号,我申请时填的是组织,没有认证也可以使用。最后登录公共平台添加通讯录,和新建应用(例如nagios),记录应用的id后面要用。用户权限什么自己设定。
微信脚本
nagios和微信平台都准备好之后,接下来下载微信命令脚本。右键点击 下载 ,保存。然后上传到nagios服务器,例如/usr/local/nagios/python/weixin目录,设置文件权限为可执行。在/usr/local/nagios/python/weixin目录新建config.py文件,添加如下配置。
#coding:utf-8 CorpID='xxxxx' Secret='xxxxxxxxxxxxxxxxx' DEBUG=0 ToUser='sijitao.net' AgentId=1
其中CorpID和Secret这两个可以通过登录微信公共平台,打开添加的应用(例如nagios)获取。
微信脚本命令传递的参数通过“-@@-”符号来分割,详细说明可以参考我的github地址:https://github.com/zhangnq/nagios/tree/master/weixin
Nagios配置
下面就是nagios上的常规配置。
commands.cfg命令文件中添加weixin命令:
define command{ command_name notify-host-by-weixin command_line /usr/local/nagios/python/weixin/NotifyByWeixin.py "host-@@-$NOTIFICATIONTYPE$-@@-$HOSTNAME$-@@-$HOSTSTATE$-@@-$HOSTADDRESS$-@@-$HOSTOUTPUT$-@@-$CONTACTALIAS$" } define command{ command_name notify-service-by-weixin command_line /usr/local/nagios/python/weixin/NotifyByWeixin.py "service-@@-$NOTIFICATIONTYPE$-@@-$SERVICEDESC$-@@-$HOSTALIAS$-@@-$HOSTADDRESS$-@@-$SERVICESTATE$-@@-$SERVICEOUTPUT$-@@-$CONTACTALIAS$" }
templates.cfg模板文件中添加联系人模板:
define contact{ name weixin-contact service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r,f,s host_notification_options d,u,r,f,s service_notification_commands notify-service-by-weixin host_notification_commands notify-host-by-weixin register 0 }
contacts.cfg联系人中添加微信通知联系人,这里alias名字要和微信公共平台通讯录中名字帐号一样才会发送成功。
define contact{ contact_name zhangnq-weixin use weixin-contact alias zhangnq email admin@sijitao.net }
最后在配置service的时候添加zhangnq-weixin这个联系人后就可以通过微信发送报警邮件了。
关于小编给大家分享的Python利用Nagios增加微信报警通知的功能就给大家介绍这么多,希望对大家有所帮助。

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond

pythonisnotpurelyLepted; itusesahybridapproachofbytecodecodecodecodecodecodedruntimerttation.1)pythoncompilessourcodeintobytecode、whodythepythonvirtualmachine(pvm).2)

ToconcatenateListsinpythothesheElements、使用:1)Operatortokeepduplicates、2)asettoremoveduplicates、or3)listcomplunting for controloverduplicates、各メトドハスディフェルフェルフェントパフォーマンスアンドソーダーインプリテーション。

pythonisantertedlanguage、useaseofuseandflexibility-butfactingporformantationationsincriticalapplications.1)解釈されたlikepythonexecuteline-by-lineを解釈します

Useforloopswhenthenumberofiterationsisknowninadvance、andwhiloopswheniterationsdependonacondition.1)forloopsareidealforsecenceslikelistoranges.2)


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。
