nagios監(jiān)控溫度腳本-創(chuàng)新互聯(lián)

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

10余年的湘橋網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。全網(wǎng)整合營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整湘橋建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)公司從事“湘橋網(wǎng)站設(shè)計”,“湘橋網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。

  由于機房溫度夏天變高了,就寫了一個腳本監(jiān)控溫度,利用nagios可以很直觀的實時監(jiān)控,同時本文對于用Python寫nagios腳本的新手來說也是個借鑒,不啰嗦了代碼如下:

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小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

新聞名稱:nagios監(jiān)控溫度腳本-創(chuàng)新互聯(lián)
鏈接分享:http://muchs.cn/article28/dsgejp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、營銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化企業(yè)網(wǎng)站制作、移動網(wǎng)站建設(shè)、建站公司

廣告

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

營銷型網(wǎng)站建設(shè)