nagios監(jiān)控溫度腳本

                              nagios監(jiān)控溫度之python腳本

創(chuàng)新互聯(lián)建站長(zhǎng)期為千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為平江企業(yè)提供專(zhuān)業(yè)的網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì),平江網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。

   由于機(jī)房溫度夏天變高了,就寫(xiě)了一個(gè)腳本監(jiān)控溫度,利用nagios可以很直觀的實(shí)時(shí)監(jiān)控,同時(shí)本文對(duì)于用Python寫(xiě)nagios腳本的新手來(lái)說(shuō)也是個(gè)借鑒,不啰嗦了代碼如下:

ps:由于涉及到密碼問(wèn)題,使用“*”來(lái)代替密碼部分:

#!/usr/bin/env python
# This file is part of the Glue Project.
# Copyright (C) by SanPolo Co.Ltd.
# All rights reserved.
#
# See http://www.spolo.org/ for more information.
#
# SanPolo Co.Ltd
# http://www.spolo.org/
# Any copyright issues, please contact: spolo@masols.com
# writed by wangzhenyu
# 2013-07-23
import os
import re
import sys
import paramiko
from optparse import OptionParser
TEMP_OK=0
TEMP_WR=1
TEMP_CR=2
TEMP_UK=3
usage=  """
    Usage: check_temp.py [-h | --help] [-H | --host]
    example: check_temp.py -H 192.168.1.4
    """
def check_temp(hostname):
    a=0
    index=0
    regex=re.compile(r'Core.*\+(\d+).*\+(\d+).*\+(\d+)')
    client=paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect('%s' % hostname, 22, username='root', password="*********", timeout=4)
    stdin,stdout,stderr = client.exec_command("sensors")
    temp=stdout.readlines()
    for line in temp:
        match=regex.search(line)
        if match == None:
            pass
        else:
            index+=1
            a+=int(match.group(1))
    result=a/index
    if result <= 50:
        print "the average temprature of core: %d" % result
        sys.exit(TEMP_OK)
    elif result >50 and result <= 60:
        print "the temprature is high"
        sys.exit(TEMP_WR)
    elif result > 60 and result <= 80:
        print "so dangerous check it right now"
        sys.exit(TEMP_CR)
    else:
        print "the temprature is very high shutdown please"
        sys.exit(TEMP_UK)
def getoption():
    parser=OptionParser(add_help_option=False)
    parser.add_option("-h",action="store_const", const=1,dest="use_way",help="%s" % usage)
    parser.add_option("-H",dest="temp_cpu")
    (options,args)=parser.parse_args()
    hostname = options.temp_cpu
    if options.use_way:
        print usage
    if options.temp_cpu:
            
        check_temp(hostname)
getoption()

網(wǎng)站標(biāo)題:nagios監(jiān)控溫度腳本
轉(zhuǎn)載來(lái)源:http://bm7419.com/article26/igiccg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、電子商務(wù)、微信小程序、網(wǎng)站策劃外貿(mào)網(wǎng)站建設(shè)、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)