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

Revision 705, 1.8 kB (checked in by jalet, 21 years ago)

Forgotten import
Bad datetime conversion

  • 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.2  2003/02/05 23:00:12  jalet
20# Forgotten import
21# Bad datetime conversion
22#
23# Revision 1.1  2003/02/05 21:28:17  jalet
24# Initial import into CVS
25#
26#
27#
28
29import os
30from pykota.requester import PyKotaRequesterError
31
32class Requester :
33    """A class to send queries to printers via SNMP."""
34    def __init__(self, config, printername) :
35        """Sets instance vars depending on the current printer."""
36        self.printername = printername
37        self.community = config.config.get(printername, "snmpcmnty")
38        self.oid = config.config.get(printername, "snmpoid")
39       
40    def getPrinterPageCounter(self, hostname) :
41        """Returns the page counter from the hostname printer via SNMP.
42       
43           Currently uses the snmpget external command. TODO : do it internally
44        """
45        if hostname is None :
46            raise PyKotaRequesterError, "Unknown printer address in SNMP(%s, %s) for printer %s" % (self.community, self.oid, self.printername)
47        answer = os.popen("snmpget -c %s -Ov %s %s" % (self.community, hostname, self.oid))
48        try :
49            pagecounter = int(answer.readline().split()[-1].strip())
50        except IndexError :   
51            raise PyKotaRequesterError, "Unable to query printer %s via SNMP(%s, %s)" % (hostname, self.community, self.oid) 
52        answer.close()
53        return pagecounter
54   
Note: See TracBrowser for help on using the browser.