[1360] | 1 | #! /usr/bin/env python |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
| 3 | # |
---|
| 4 | # PyKota |
---|
| 5 | # |
---|
| 6 | # PyKota : Print Quotas for CUPS and LPRng |
---|
| 7 | # |
---|
[2028] | 8 | # (c) 2003, 2004, 2005 Jerome Alet <alet@librelogiciel.com> |
---|
[1360] | 9 | # This program is free software; you can redistribute it and/or modify |
---|
| 10 | # it under the terms of the GNU General Public License as published by |
---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | # (at your option) any later version. |
---|
| 13 | # |
---|
| 14 | # This program is distributed in the hope that it will be useful, |
---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | # GNU General Public License for more details. |
---|
| 18 | # |
---|
| 19 | # You should have received a copy of the GNU General Public License |
---|
| 20 | # along with this program; if not, write to the Free Software |
---|
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | # |
---|
| 23 | # $Id$ |
---|
| 24 | # |
---|
| 25 | # |
---|
| 26 | |
---|
| 27 | import sys |
---|
| 28 | import os |
---|
| 29 | import time |
---|
| 30 | |
---|
| 31 | OIDS = ["hrPrinterDetectedErrorState", "hrPrinterStatus", "hrDeviceStatus"] |
---|
| 32 | SNMPCOMMAND = "snmpget -v1 -c public -Ov %(printer)s HOST-RESOURCES-MIB::%(oid)s.1" |
---|
| 33 | |
---|
| 34 | def main() : |
---|
| 35 | if len(sys.argv) != 2 : |
---|
| 36 | sys.stderr.write("usage : snmpprinterstatus yourprinter.example.com\n") |
---|
| 37 | else : |
---|
| 38 | printer = sys.argv[1] |
---|
| 39 | while 1 : |
---|
| 40 | try : |
---|
| 41 | for oid in OIDS : |
---|
| 42 | command = SNMPCOMMAND % locals() |
---|
| 43 | output = os.popen(command) |
---|
| 44 | result = output.read().strip() |
---|
| 45 | status = output.close() |
---|
| 46 | print oid, "===>", result |
---|
| 47 | except KeyboardInterrupt : |
---|
| 48 | break |
---|
| 49 | time.sleep(0.5) |
---|
| 50 | |
---|
| 51 | if __name__ == "__main__" : |
---|
| 52 | sys.exit(main()) |
---|