真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

利用python將mysql數(shù)據(jù)進行抽取并清理成標準格式后存入MSSql數(shù)據(jù)中

from pymongo import MongoClient
from pyMySQL import connect
import pymssql
from datetime import datetime, timedelta
import time

十余年的深州網(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)站推廣”以來,每個客戶項目都認真落實執(zhí)行。

Nagios 數(shù)據(jù)庫的IP 地址

NagiosDB_IP = ["10.1.1.44", "10.1.1.37"]

用于數(shù)據(jù)展示的BI 中間數(shù)據(jù)庫地址及賬號信息

BIDBServer='10.1.1.65'
BI_NagiosDB='NagiosInfo'
NagiosDB='nagios'
BIDB_User='sa'
BIDBPassword='123456!a'
NagiosDB_User='report'
NagiosDBPassword='report!a'

鏈接中間數(shù)據(jù)庫,該庫用于存放Nagios 性能數(shù)據(jù)

Mssqlconn=pymssql.connect(host=BIDBServer,database=BI_NagiosDB,user=BIDB_User,password=BIDBPassword)

查詢交換機端口狀態(tài)信息

Querys_SwitchPortStatus = """SELECT NSS.service_object_id,NSS.status_update_time,NSS.output,NS.display_name,NH.display_name, NH.address ,NS.host_object_id, NSS.check_command from nagios_servicestatus NSS
LEFT join
nagios_services NS on NSS.service_object_id = NS.service_object_id
LEFT join
nagios_hosts NH on NS.host_object_id = NH.host_object_id
where (check_command LIKE 'check_snmp_free_interfaces%' or check_command LIKE 'check_snmp_usage_interfaces%')
ORDER BY
NH.display_name"""

查詢交換機基礎(chǔ)信息

Querys_SwitchInfo = """SELECT NSS.service_object_id,NSS.status_update_time,NSS.output,NS.display_name,NH.display_name, NH.address ,NS.host_object_id, NSS.check_command from nagios_servicestatus NSS
LEFT join
nagios_services NS on NSS.service_object_id = NS.service_object_id
LEFT join
nagios_hosts NH on NS.host_object_id = NH.host_object_id
where (check_command LIKE 'snmp_cisco_info%' AND NS.display_name LIKE '1.1.2-Network Access Switch Info%')
ORDER BY
NH.display_name
"""

查詢主機狀態(tài)信息

Querys_HostStatus = """select host_object_id,status_update_time,output from nagios_hoststatus WHERE check_command LIKE 'check-host-alive%'"""

Mssqlconn=pymssql.connect(host='.',database='NagiosInfo',user='sa',password='123456!a')

Mssqlcur=Mssqlconn.cursor()

def Port_Status_DataClean():

start=time.strftime("%Y%m%d",(datetime.now()-timedelta(1)).timetuple())

    # end=time.strftime("%Y%m%d",datetime.now().timetuple())
    # t1=datetime.now()
    Port_Status= 'Unknown'
    for i in range(len(NagiosDB_IP)):
        conn=connect(NagiosDB_IP[i], NagiosDB_User, NagiosDBPassword, NagiosDB, charset='utf8')
        cursor=conn.cursor()
        cursor.execute(Querys_SwitchPortStatus)
        for row in cursor:
        #     print(row)
            record= {}
            record['Object_ID']=row[0]
            record['Record_Time']=row[1]
            record['Service_Name']=row[3]
            record['Host_Name']=row[4]
            record['IP_Addr']=row[5]
            record['Host_ID']=row[6]
            #record['Check_Command']=row[7]
            if row[7].split('!')[0]== 'check_snmp_free_interfaces':
                Port_Status='Free'
            elif row[7].split('!')[0]=='check_snmp_usage_interfaces':
                Port_Status='Usage'
            try:
                for Port in row[2].split('(0')[1].strip(')').split():
                    record["Port_Status"]= Port_Status
                    record['Port']=Port
                    Mssqlcur.execute("insert into ASwitchPortStatus values ('%s','%s','%s','%s','%s','%s','%s','%s')"%(record['Object_ID'],record['Record_Time'],record['Service_Name'],record['Host_Name'],record['IP_Addr'],record['Host_ID'],record["Port_Status"],record['Port']) )
            except:
                # print(row[2])
                continue
        Mssqlcur.connection.commit()
        conn.close()

def SwitchInfo_DataClean():

start=time.strftime("%Y%m%d",(datetime.now()-timedelta(1)).timetuple())

# end=time.strftime("%Y%m%d",datetime.now().timetuple())
# t1=datetime.now()

for i in range(len(NagiosDB_IP)):
    conn = connect(NagiosDB_IP[i], "client", "client!a", "nagios", charset='utf8')
    cursor = conn.cursor()
    cursor.execute(Querys_SwitchInfo)
    for row in cursor:
        record = {}
        record['Object_ID'] = row[0]
        record['Record_Time'] = row[1]
        record['Service_Name'] = row[3]
        record['Host_Name'] = row[4]
        record['IP_Addr'] = row[5]
        record['Host_ID'] = row[6]
        try:
                record['Host_Info_Name']=row[2].split(',
')[0] record['Host_Info_Model'] = row[2].split(',
')[1] record['Host_Info_Version']=row[2].split(',
')[2] record['Host_Info_SN'] = row[2].split(',
')[3] record['Host_Info_location'] = row[2].split(',
')[4] record['Host_Info_Contact'] = row[2].split(',
')[5] Mssqlcur.execute("insert into ASwitchInfo values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"%(record['Object_ID'], record['Record_Time'], record['Service_Name'], record['Host_Name'],record['IP_Addr'], record['Host_ID'], record['Host_Info_Name'], record['Host_Info_Model'],record['Host_Info_Version'], record['Host_Info_SN'], record['Host_Info_location'],record['Host_Info_Contact'])) except: continue Mssqlcur.connection.commit() conn.close()

def HostStatus_DataClean():

start=time.strftime("%Y%m%d",(datetime.now()-timedelta(1)).timetuple())

# end=time.strftime("%Y%m%d",datetime.now().timetuple())
# t1=datetime.now()

for i in range(len(NagiosDB_IP)):
    conn = connect(NagiosDB_IP[i], "client", "client!a", "nagios", charset='utf8')
    cursor = conn.cursor()
    cursor.execute(Querys_HostStatus)
    for row in cursor:
        record = {}
        record['Host_ID'] = row[0]
        record['Record_Time'] = row[1]
        try:
            if row[2].split(' - ')[0]== 'OK':
                record['Host_Status']='UP'
            elif row[2].split(' - ')[0]== 'CRITICAL':
                record['Host_Status'] = 'Down'
            else:
                record['Host_Status'] = '#N/A'
        except:
            continue
        Mssqlcur.execute("insert into HostStatus values('%s','%s','%s')" %(record['Host_ID'], record['Record_Time'], record['Host_Status']))
        print(record)
    Mssqlcur.connection.commit()
    conn.close()

if name=="main":
Port_Status_DataClean()
SwitchInfo_DataClean()
HostStatus_DataClean()


網(wǎng)頁名稱:利用python將mysql數(shù)據(jù)進行抽取并清理成標準格式后存入MSSql數(shù)據(jù)中
分享地址:http://weahome.cn/article/gegigg.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部