root / pykota / trunk / pykota / requesters / snmp.py @ 789

Revision 789, 2.2 kB (checked in by jalet, 21 years ago)

Moved some code down into the requesters

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#! /usr/bin/env python
2
3# PyKota - Print Quotas for CUPS
4#
5# (c) 2003 Jerome Alet <alet@librelogiciel.com>
6# You're welcome to redistribute this software under the
7# terms of the GNU General Public Licence version 2.0
8# or, at your option, any higher version.
9#
10# You can read the complete GNU GPL in the file COPYING
11# which should come along with this software, or visit
12# the Free Software Foundation's WEB site http://www.fsf.org
13#
14# $Id$
15#
16# $Log$
17# Revision 1.6  2003/02/10 11:47:39  jalet
18# Moved some code down into the requesters
19#
20# Revision 1.5  2003/02/10 00:42:17  jalet
21# External requester should be ok (untested)
22# New syntax for configuration file wrt requesters
23#
24# Revision 1.4  2003/02/09 13:05:43  jalet
25# Internationalization continues...
26#
27# Revision 1.3  2003/02/07 13:12:41  jalet
28# Bad old comment
29#
30# Revision 1.2  2003/02/05 23:00:12  jalet
31# Forgotten import
32# Bad datetime conversion
33#
34# Revision 1.1  2003/02/05 21:28:17  jalet
35# Initial import into CVS
36#
37#
38#
39
40import os
41from pykota.requester import PyKotaRequesterError
42
43class Requester :
44    """A class to send queries to printers via SNMP."""
45    def __init__(self, config, printername, arguments) :
46        """Sets instance vars depending on the current printer."""
47        self.printername = printername
48        args = [x.strip() for x in arguments.split(',')]
49        self.community = args[0]
50        self.oid = args[1]
51       
52    def getPrinterPageCounter(self, hostname) :
53        """Returns the page counter from the hostname printer via SNMP.
54       
55           Currently uses the snmpget external command. TODO : do it internally
56        """
57        if hostname is None :
58            raise PyKotaRequesterError, _("Unknown printer address in SNMP(%s, %s) for printer %s") % (self.community, self.oid, self.printername)
59        answer = os.popen("snmpget -c %s -Ov %s %s" % (self.community, hostname, self.oid))
60        try :
61            pagecounter = int(answer.readline().split()[-1].strip())
62        except IndexError :   
63            raise PyKotaRequesterError, _("Unable to query printer %s via SNMP(%s, %s)") % (hostname, self.community, self.oid) 
64        answer.close()
65        return pagecounter
66   
Note: See TracBrowser for help on using the browser.