nagios監(jiān)控溫度之python腳本
由于機(jī)房溫度夏天變高了,就寫了一個(gè)腳本監(jiān)控溫度,利用nagios可以很直觀的實(shí)時(shí)監(jiān)控,同時(shí)本文對于用Python寫nagios腳本的新手來說也是個(gè)借鑒,不啰嗦了代碼如下:
ps:由于涉及到密碼問題,使用“*”來代替密碼部分:
#!/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ù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
新聞名稱:nagios監(jiān)控溫度腳本-創(chuàng)新互聯(lián)
鏈接分享:http://chinadenli.net/article28/dsgejp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、營銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、企業(yè)網(wǎng)站制作、移動(dòng)網(wǎng)站建設(shè)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容