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

Revision 695, 1.7 kB (checked in by jalet, 21 years ago)

Initial import into CVS

  • 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 accounting filter
4#
5# PyKota - Print Quotas for CUPS
6#
7# (c) 2003 Jerome Alet <alet@librelogiciel.com>
8# You're welcome to redistribute this software under the
9# terms of the GNU General Public Licence version 2.0
10# or, at your option, any higher version.
11#
12# You can read the complete GNU GPL in the file COPYING
13# which should come along with this software, or visit
14# the Free Software Foundation's WEB site http://www.fsf.org
15#
16# $Id$
17#
18# $Log$
19# Revision 1.1  2003/02/05 21:28:17  jalet
20# Initial import into CVS
21#
22#
23#
24
25from pykota.requester import PyKotaRequesterError
26
27class Requester :
28    """A class to send queries to printers via SNMP."""
29    def __init__(self, config, printername) :
30        """Sets instance vars depending on the current printer."""
31        self.printername = printername
32        self.community = config.config.get(printername, "snmpcmnty")
33        self.oid = config.config.get(printername, "snmpoid")
34       
35    def getPrinterPageCounter(self, hostname) :
36        """Returns the page counter from the hostname printer via SNMP.
37       
38           Currently uses the snmpget external command. TODO : do it internally
39        """
40        if hostname is None :
41            raise PyKotaRequesterError, "Unknown printer address in SNMP(%s, %s) for printer %s" % (self.community, self.oid, self.printername)
42        answer = os.popen("snmpget -c %s -Ov %s %s" % (self.community, hostname, self.oid))
43        try :
44            pagecounter = int(answer.readline().split()[-1].strip())
45        except IndexError :   
46            raise PyKotaRequesterError, "Unable to query printer %s via SNMP(%s, %s)" % (hostname, self.community, self.oid) 
47        answer.close()
48        return pagecounter
49   
Note: See TracBrowser for help on using the browser.