From 2b38e5c8b077cc03612388daf1c9c34f08688fef Mon Sep 17 00:00:00 2001 From: Evan Broder Date: Sat, 4 Oct 2008 20:13:08 -0400 Subject: [PATCH] Use the syslog module instead of the event_logger module svn path=/trunk/packages/sipb-xen-dhcp/; revision=1034 --- code/dhcpserver.py | 41 +++++++++++++++----------------- code/event_logger.py | 63 -------------------------------------------------- debian/changelog | 3 ++- 3 files changed, 21 insertions(+), 86 deletions(-) delete mode 100644 code/event_logger.py diff --git a/code/dhcpserver.py b/code/dhcpserver.py index 634cad6..d5f35eb 100755 --- a/code/dhcpserver.py +++ b/code/dhcpserver.py @@ -9,10 +9,7 @@ from pydhcplib.type_strlist import strlist import socket import IN -import event_logger -if '__main__' == __name__: - event_logger.init("stdout", 'DEBUG', {}) -from event_logger import Log +import syslog as s import psycopg2 import time @@ -50,7 +47,7 @@ class DhcpBackend: for line in open('/proc/net/route'): parts = line.split() if parts[1] == ipstr: - Log.Output(Log.debug, "find_interface found "+str(nic.ip)+" on "+parts[0]) + s.syslog(s.LOG_DEBUG, "find_interface found "+str(nic.ip)+" on "+parts[0]) return parts[0] return @@ -107,7 +104,7 @@ class DhcpBackend: return options def Discover(self, packet): - Log.Output(Log.debug,"dhcp_backend : Discover ") + s.syslog(s.LOG_DEBUG, "dhcp_backend : Discover ") chaddr = hwmac(packet.GetHardwareAddress()) nic = self.findNIC(str(chaddr)) if nic is None or nic.machine is None: @@ -130,7 +127,7 @@ class DhcpBackend: options['domain_search'] = [config.dhcp.search_domain] if ip is not None: ip = ipv4(ip) - Log.Output(Log.debug,"dhcp_backend : Discover result = "+str(ip)) + s.syslog(s.LOG_DEBUG,"dhcp_backend : Discover result = "+str(ip)) packet_parameters = self.getParameters(**options) # FIXME: Other offer parameters go here @@ -141,7 +138,7 @@ class DhcpBackend: return False def Request(self, packet): - Log.Output(Log.debug, "dhcp_backend : Request") + s.syslog(s.LOG_DEBUG, "dhcp_backend : Request") discover = self.Discover(packet) @@ -152,14 +149,14 @@ class DhcpBackend: yiaddr = packet.GetOption("yiaddr") if not discover: - Log.Output(Log.info,"Unknown MAC address: "+str(chaddr)) + s.syslog(s.LOG_INFO,"Unknown MAC address: "+str(chaddr)) return False if yiaddr!="0.0.0.0" and yiaddr == request : - Log.Output(Log.info,"Ack ip "+str(yiaddr)+" for "+str(chaddr)) + s.syslog(s.LOG_INFO,"Ack ip "+str(yiaddr)+" for "+str(chaddr)) return True else: - Log.Output(Log.info,"Requested ip "+str(request)+" not available for "+str(chaddr)) + s.syslog(s.LOG_INFO,"Requested ip "+str(request)+" not available for "+str(chaddr)) return False def Decline(self, packet): @@ -172,7 +169,7 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer): def __init__(self, backend, options = {'client_listenport':68,'server_listenport':67}): pydhcplib.dhcp_network.DhcpServer.__init__(self,"0.0.0.0",options["client_listen_port"],options["server_listen_port"],) self.backend = backend - Log.Output(Log.debug, "__init__ DhcpServer") + s.syslog(s.LOG_DEBUG, "__init__ DhcpServer") def SendDhcpPacketTo(self, To, packet): intf = self.backend.find_interface(packet) @@ -197,12 +194,12 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer): if giaddr!=[0,0,0,0] : agent_ip = ".".join(map(str,giaddr)) self.SendDhcpPacketTo(agent_ip,packet) - Log.Output(Log.debug, "SendPacket to agent : "+agent_ip) + s.syslog(s.LOG_DEBUG, "SendPacket to agent : "+agent_ip) # FIXME: This shouldn't broadcast if it has an IP address to send # it to instead. See RFC2131 part 4.1 for full details else : - Log.Output(Log.debug, "No agent, broadcast packet.") + s.syslog(s.LOG_DEBUG, "No agent, broadcast packet.") self.SendDhcpPacketTo("255.255.255.255",packet) @@ -212,7 +209,7 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer): logmsg = "Get DHCPDISCOVER packet from " + hwmac(packet.GetHardwareAddress()).str() - Log.Output(Log.info, logmsg) + s.syslog(s.LOG_INFO, logmsg) offer = DhcpPacket() offer.CreateDhcpOfferPacketFrom(packet) @@ -232,15 +229,15 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer): #packet.PrintOptions() if sid != [0,0,0,0] and ciaddr == [0,0,0,0] : - Log.Output(Log.info, "Get DHCPREQUEST_SELECTING_STATE packet") + s.syslog(s.LOG_INFO, "Get DHCPREQUEST_SELECTING_STATE packet") elif sid == [0,0,0,0] and ciaddr == [0,0,0,0] and ip : - Log.Output(Log.info, "Get DHCPREQUEST_INITREBOOT_STATE packet") + s.syslog(s.LOG_INFO, "Get DHCPREQUEST_INITREBOOT_STATE packet") elif sid == [0,0,0,0] and ciaddr != [0,0,0,0] and not ip : - Log.Output(Log.info,"Get DHCPREQUEST_INITREBOOT_STATE packet") + s.syslog(s.LOG_INFO,"Get DHCPREQUEST_INITREBOOT_STATE packet") - else : Log.Output(Log.info,"Get DHCPREQUEST_UNKNOWN_STATE packet : not implemented") + else : s.syslog(s.LOG_INFO,"Get DHCPREQUEST_UNKNOWN_STATE packet : not implemented") if self.backend.Request(packet) : packet.TransformToDhcpAckPacket() else : packet.TransformToDhcpNackPacket() @@ -251,15 +248,15 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer): # FIXME: These are not yet implemented. def HandleDhcpDecline(self, packet): - Log.Output(Log.info, "Get DHCPDECLINE packet") + s.syslog(s.LOG_INFO, "Get DHCPDECLINE packet") self.backend.Decline(packet) def HandleDhcpRelease(self, packet): - Log.Output(Log.info,"Get DHCPRELEASE packet") + s.syslog(s.LOG_INFO,"Get DHCPRELEASE packet") self.backend.Release(packet) def HandleDhcpInform(self, packet): - Log.Output(Log.info, "Get DHCPINFORM packet") + s.syslog(s.LOG_INFO, "Get DHCPINFORM packet") if self.backend.Request(packet) : packet.TransformToDhcpAckPacket() diff --git a/code/event_logger.py b/code/event_logger.py deleted file mode 100644 index fa59be0..0000000 --- a/code/event_logger.py +++ /dev/null @@ -1,63 +0,0 @@ -# Anemon Dhcp -# Copyright (C) 2005 Mathieu Ignacio -- mignacio@april.org -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA - -import sys -from logging import * - - - -class EventLogger: - def __init__(self,logtype="stdout",loglevel=WARNING,option={}): - self.loglevel = loglevel - self.logtype = logtype - - self.info = INFO - self.debug = DEBUG - self.warn = WARN - self.error = ERROR - self.critical = CRITICAL - - - self.logger = getLogger('SipbXenDhcpServer') - - if logtype == "file" : - # into file logger - handler = FileHandler(option["log_file"]) - - elif logtype == "syslog" : - handler = SysLogHandler((option["log_host"],option["log_port"])) - - elif logtype == "http" : - handler = HTTPHandler(option["log_host"],option["log_url"],option["log_method"]) - - else : # logtype == "stdout" : - handler = StreamHandler() - - - - handler.setFormatter(Formatter('%(asctime)s %(levelname)s %(message)s')) - self.logger.addHandler(handler) - self.logger.setLevel(loglevel) - - def Output(self,level,infostring) : - self.logger.log(level,infostring) - -def init(logtype,level,path): - global Log - - Log = EventLogger(logtype,eval(level),path) - Log.Output(INFO,"EventLogger : Started.") diff --git a/debian/changelog b/debian/changelog index 669e624..3dbbe51 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,9 @@ sipb-xen-dhcp (3) unstable; urgency=low * invirt-configurize dhcp + * Use the syslog instead of the event_logger module - -- Evan Broder Sat, 04 Oct 2008 19:55:49 -0400 + -- Evan Broder Sat, 04 Oct 2008 20:08:29 -0400 sipb-xen-dhcp (2) unstable; urgency=low -- 1.7.9.5