Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Benjamin Graillot
scripts
Commits
95234963
Commit
95234963
authored
Oct 31, 2013
by
Vincent Le gallic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "[arpwatch] On n'envoie pas de mail pour les évènement inintéressants."
This reverts commit
7560f05a
.
parent
a0778565
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
47 deletions
+10
-47
firewall/aiccu_postup
firewall/aiccu_postup
+1
-1
gestion/ressuscite.py
gestion/ressuscite.py
+1
-1
secours/secours.py
secours/secours.py
+2
-1
surveillance/arpwatch/report.py
surveillance/arpwatch/report.py
+6
-44
No files found.
firewall/aiccu_postup
View file @
95234963
...
...
@@ -5,4 +5,4 @@
/etc/init.d/netacct-crans-sixxs2 restart
/etc/init.d/firewall6 restart
#
/usr/sbin/monit monitor netacct-crans-sixxs2
/usr/sbin/monit monitor netacct-crans-sixxs2
gestion/ressuscite.py
View file @
95234963
...
...
@@ -361,7 +361,7 @@ def ressuscite(adh, oldmachine):
except
EnvironmentError
,
c
:
err
+=
c
.
args
[
0
]
+
'
\n
'
elif
len
(
c
.
args
)
>
1
and
c
.
args
[
1
]
==
3
and
isadm
:
# Mac douteuse
no
=
dlg
.
yesno
(
text
=
u
"L
\'
adresse MAC ne correspond à aucun constructeur, continuer ?"
,
no
,
res
=
dlg
.
yesno
(
text
=
u
"L
\'
adresse MAC ne correspond à aucun constructeur, continuer ?"
,
title
=
u
"Adresse MAC"
)
if
not
no
:
try
:
machine
.
mac
(
str
(
oldmachine
.
mac
()),
1
)
...
...
secours/secours.py
View file @
95234963
...
...
@@ -76,7 +76,8 @@ COMMANDES = {
'/etc/init.d/postfix restart'
,
],
'komaz'
:
[
'/usr/bin/monit start netacct-crans-sixxs2'
,
'/etc/init.d/aiccu restart'
,
'/usr/bin/monit monitor netacct-crans-sixxs2'
,
],
}.
get
(
HOSTNAME
,
[])
...
...
surveillance/arpwatch/report.py
View file @
95234963
...
...
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Ajout d'un whos et d'un tracage aux mails d'arpwatch
# Auteurs : Stéphane Glondu, Cyril Cohen, Daniel STAN, Valentin Samir
, Vincent Le Gallic
# Auteurs : Stéphane Glondu, Cyril Cohen, Daniel STAN, Valentin Samir
# Licence : GPLv2
from
__future__
import
print_function
...
...
@@ -14,7 +14,7 @@ import common
sys
.
path
.
append
(
'/usr/scripts'
)
from
gestion.tools.locate_mac
import
trace_machine
,
format_mac
,
info_machine
import
gestion.config
from
gestion.config
import
NETs
from
gestion.iptools
import
AddrInNets
from
utils.sendmail
import
sendmail
...
...
@@ -26,14 +26,7 @@ if not recipients:
find_mac
=
re
.
compile
(
r
'[0-9A-Fa-f]{1,2}(?::[0-9A-Fa-f]{1,2}){5}'
)
find_ip
=
re
.
compile
(
r
'[0-9]{1,3}(?:\.[0-9]{1,3}){3}'
)
#: Regexp pour matcher l'interface.
#: Ne matche pas toutes les interface (si un jour eth1 poppe),
#: Mais de toutes façons on ne drope que des interfaces qu'on a réussi à identifier
find_iface
=
re
.
compile
(
r
'eth0(?:\.[0-9]+)?'
)
arpwatched_nets
=
sum
([
gestion
.
config
.
NETs
[
nom
]
for
nom
in
[
'all'
,
'adm'
,
'accueil'
,
'isolement'
,
'personnel-ens'
,
'evenementiel'
]],
[])
#: VLANS dont on ignore les "new station"/"new activity" *si elles ont une ip correspondant au vlan*
ignored_vlans
=
[
'accueil'
,
'wifi'
]
arpwatched_net
=
NETs
[
'all'
]
+
NETs
[
'adm'
]
+
NETs
[
'accueil'
]
+
NETs
[
'isolement'
]
+
NETs
[
'personnel-ens'
]
+
NETs
[
'evenementiel'
]
def
get_machine
(
unformated_mac
):
"""Renvoie les informations sur la machine à partir de sa mac"""
...
...
@@ -46,37 +39,6 @@ def get_subject(headers_list):
return
line
[
9
:].
strip
()
return
None
def
drop_report
(
subject
,
ip
):
"""Détermine à partir du ``subject`` du mail
si il n'est pas nécessaire d'envoyer une notification pour cet évènement.
Renvoie ``True`` si il faut le dropper.
"""
# On récupère l'interface et l'ip dans le sujet
ifaces
=
find_iface
.
findall
(
subject
)
iface
=
ifaces
[
0
]
if
ifaces
else
None
if
not
iface
is
None
:
# On détermine le vlan
vlans
=
re
.
findall
(
r
"\.([^\.]*)$"
,
iface
)
try
:
vlan
=
int
(
vlans
[
0
])
if
vlans
else
None
except
ValueError
:
vlan
=
None
ips
=
find_ip
.
findall
(
subject
)
ip
=
ips
[
0
]
if
ips
else
None
#print("%r, %r" % (ip, iface))
#print(arpwatched_nets)
if
u
"new station"
in
subject
or
"new activity"
in
subject
:
if
not
vlan
is
None
:
vlannames
=
[
k
for
(
k
,
v
)
in
gestion
.
config
.
vlans
.
iteritems
()
if
v
==
vlan
]
#print("vlannames : %r" % vlannames)
if
vlannames
and
vlannames
[
0
]
in
ignored_vlans
:
#print("%r in %r ?" % (ip, gestion.config.NETs[vlannames[0]]))
if
AddrInNets
(
ip
,
gestion
.
config
.
NETs
[
vlannames
[
0
]]):
# On ignore les new station dont l'IP est sur le bon vlan
return
True
return
False
def
report
(
texte
,
fallback
=
False
):
"""Envoi d'un rapport"""
textes
=
texte
.
splitlines
(
True
)
...
...
@@ -97,8 +59,8 @@ def report(texte, fallback=False):
ip
=
set
(
find_ip
.
findall
(
texte
)).
pop
()
except
KeyError
:
ip
=
None
# On complète le message
seulement en cas de flip flop
if
u
'flip flop'
in
subject
and
ip
is
not
None
and
AddrInNets
(
ip
,
arpwatched_net
s
):
# On complète le message
if
u
'flip flop'
in
subject
and
ip
is
not
None
and
AddrInNets
(
ip
,
arpwatched_net
):
try
:
macs
=
find_mac
.
findall
(
texte
)
for
mac
in
macs
:
...
...
@@ -113,7 +75,7 @@ def report(texte, fallback=False):
textes
.
append
(
u
'
\n
--
\n
arpwatch_sendmail.py
\n
'
)
out
=
''
.
join
(
textes
)
if
recipients
and
not
drop_report
()
:
if
recipients
:
sendmail
(
u
"arpwatch@crans.org"
,
recipients
,
subject
,
out
,
more_headers
=
{
'X-Mailer'
:
__file__
,
...
...
Write
Preview
Markdown
is supported
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