Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Leo Colisson
scripts
Commits
6a51e0c5
Commit
6a51e0c5
authored
Sep 27, 2015
by
Pierre-Elliott Bécue
Browse files
Patch pour batb-5.crans.org
parent
ed91745f
Changes
1
Hide whitespace changes
Inline
Side-by-side
surveillance/mac_prises/mac_prise.py
View file @
6a51e0c5
...
...
@@ -9,9 +9,12 @@
# celle-ci, démerdez-vous avec un des responsables de
# l'association pour les fioritures.
import
os
,
sys
import
os
import
sys
import
sys
import
re
import
socket
from
commands
import
getstatusoutput
# 1 avril 2012 - PEB :
...
...
@@ -21,6 +24,13 @@ from commands import getstatusoutput
# (plante lamentablement quand j'essaye avec mon compte sur vo, sous
# ipython. Mais si je sudo ipython, ça marche...
def
host_exists
(
hostname
):
"""Vérifie si hostname résout bien, sinon retourne false"""
try
:
socket
.
gethostbyname
(
hostname
)
except
socket
.
gaierror
:
return
False
def
liste_chambres_macs
(
switch
,
annuaire
):
u
'''
Fonction générant un dictionnaire (macs) contenant pour chaque prise une
...
...
@@ -29,11 +39,15 @@ def liste_chambres_macs(switch, annuaire):
multiples connexions sql pour rien.
'''
liste_bats
=
[
'a'
,
'b'
,
'c'
,
'g'
,
'h'
,
'i'
,
'j'
,
'm'
,
'p'
]
split
=
switch
.
replace
(
'.adm.crans.org'
,
''
).
split
(
'-'
)
bat
,
num_switch
=
split
[
0
][
-
1
],
int
(
split
[
1
][
0
])
if
bat
not
in
liste_bats
:
return
{}
if
not
host_exists
(
switch
):
switch
=
switch
.
replace
(
'adm.crans.org'
,
'crans.org'
)
if
not
host_exists
(
switch
):
return
{}
data
=
walk
(
switch
,
'STATISTICS-MIB::hpSwitchPortFdbAddress'
)
liste_chbres
=
[]
...
...
@@ -84,7 +98,6 @@ def walk(host, oid):
if
not
re
.
match
(
'([0-9a-f]{2}){6}'
,
mac
):
mac
=
mac
.
encode
(
'hex'
).
lower
()
mac
=
"%s:%s:%s:%s:%s:%s"
%
(
mac
[
0
:
2
],
mac
[
2
:
4
],
mac
[
4
:
6
],
mac
[
6
:
8
],
mac
[
8
:
10
],
mac
[
10
:
12
])
if
not
result
.
has_key
(
port
):
result
[
port
]
=
[
mac
]
else
:
...
...
@@ -92,7 +105,7 @@ def walk(host, oid):
except
:
print
"Ligne moisie : %s de l'hôte : %s"
%
(
ligne
,
host
)
return
result
def
__exec
(
cmd
):
u
'''
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment