[printer_watch] script d'envoi de mail lorsque l'imprimante est down
This commit is contained in:
parent
5810ffa5e3
commit
d04d51a2c3
1 changed files with 18 additions and 0 deletions
18
impression/printer_watch.py
Executable file
18
impression/printer_watch.py
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash /usr/scripts/python.sh
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import netsnmp
|
||||||
|
import sys
|
||||||
|
from utils import sendmail
|
||||||
|
|
||||||
|
# On checke le statut de l'imprimante, si elle est down (5) on envoie des mails.
|
||||||
|
status_id = netsnmp.Varbind("hrDeviceStatus.1")
|
||||||
|
if netsnmp.snmpget(status_id, Version=1, DestHost="imprimante.adm", Community="public") == ('5',):
|
||||||
|
# On récolte la liste des erreurs dans cette branche
|
||||||
|
errors = netsnmp.snmpwalk(netsnmp.Varbind("mib-2.43.18.1.1.8.1"), Version=1, DestHost="imprimante.adm", Community="public")
|
||||||
|
errors_list = [error + '\n' for error in errors]
|
||||||
|
|
||||||
|
msg = """ L'imprimante est actuellement hors service. Les erreurs suivantes se sont produites:
|
||||||
|
%s""" % ''.join(errors_list)
|
||||||
|
|
||||||
|
sendmail.sendmail(u"imprimante.adm@crans.org", u"impression@lists.crans.org", u"Imprimante hors service", msg)
|
Loading…
Add table
Add a link
Reference in a new issue