-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
52 lines (42 loc) · 1.77 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#/usr/bin/python
# -*- coding: utf-8 -*-
#########################
# Fonctions pour appsnmp#
# Karim Ayari #
# DSI #
# Rectorat de Lyon #
#########################
def getsnmp(iprouteur):
"""
Récupere les informations sur le routeur en snmp
"""
from commands import getoutput
community=""
ref=getoutput("snmpwalk -v2c -c %s %s sysName.0 |awk -F\"=\" '{print $2}' |awk -F\":\" '{print $2}'|awk -F\"-\" '{print $1}'" % (community,iprouteur)).replace(' ','')
lbb=getoutput("snmpwalk -v2c -c %s %s sysName.0 |awk -F\"=\" '{print $2}' |awk -F\":\" '{print $2}'|awk -F\"-\" '{print $2}'" % (community,iprouteur)).replace(' ','')
ip=getoutput("snmpwalk -v2c -c %s %s SNMPv2-SMI::mib-2.15.4.0 |awk -F\"=\" '{print $2}' |awk -F\":\" '{print $2}'" % (community,iprouteur)).replace(' ','')
upt="#upt "+getoutput("snmpwalk -v2c -c %s %s sysUpTimeInstance |awk -F\"=\" '{print $2}' |awk '{print $3\" \"$4\" \"$5}'" % (community,iprouteur)).replace('#upt','')
return ref,lbb,ip,upt
def basetab(ip):
"""
Connexion a la base de donnees
"""
from MySQLdb import connect
# Open database connection
db = connect("localhost","login","mdp","bd" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
# execute SQL query using execute() method.
cursor.execute("SELECT idLien,ip_gw,ref_operateur,ip_routeur_lo,nom,Type_Routeur from amon where ip_gw like '%s'" % ip)
# Fetch a single row using fetchone() method.
data = cursor.fetchone()
# disconnect from server
db.close()
return data
def fping(ipsup):
"""
Test de la supervision du routeur
"""
from commands import getstatusoutput
state_ping,y=getstatusoutput('fping %s' % ipsup)
return state_ping