Package Products :: Package ZenModel :: Module IpServiceLoader |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.IpServiceLoader

     1  ###########################################################################
     2  #
     3  # This program is part of Zenoss Core, an open source monitoring platform.
     4  # Copyright (C) 2007, Zenoss Inc.
     5  #
     6  # This program is free software; you can redistribute it and/or modify it
     7  # under the terms of the GNU General Public License version 2 or (at your
     8  # option) any later version as published by the Free Software Foundation.
     9  #
    10  # For complete information please visit: http://www.zenoss.com/oss/
    11  #
    12  ###########################################################################
    13
    14  __doc__ ='''IpServiceLoader
    15
    16  A script to load the IANA well known port numbers.
    17
    18  $Id: IpServiceLoader.py,v 1.5 2004/04/15 23:47:50 edahl Exp $'''
    19
    20  __version__ = "$Revision: 1.5 $"[11:-2]
    21
    22  import os
    23  import re
    24
    25  import Globals #initalize imports correctly magic!
    26
    27  from Products.ZenUtils.BasicLoader import BasicLoader
    28
    29  from Products.ZenModel.IpService import getIpServiceKey
    30  from Products.ZenModel.IpServiceClass import IpServiceClass
    31
    32 -class IpServiceLoader(BasicLoader):
    33
    34      lineparse = re.compile(r"^(\S+)\s+(\d+)/(\S+)(.*)")
    35
    36
    37 -    def __init__(self, noopts=0, app=None):
    38          self.filename = os.path.join(os.path.dirname(__file__),
    39                              "port-numbers.txt")
    40          BasicLoader.__init__(self, noopts, app, ignoreComments=False)
    41          services = self.dmd.getDmdRoot('Services')
    42          self.privserv = services.createOrganizer("/IpService/Privileged")
    43          self.regserv = services.createOrganizer("/IpService/Registered")
    44          self.lastservice = None
    45
    46
    47 -    def loaderBody(self, line):
    48          if line.startswith("#"): return
    49          m = self.lineparse.search(line)
    50          if not m: return
    51          keyword, port, proto, descr = m.groups()
    52          descr = descr.strip()
    53          port = int(port)
    54          svc = self.privserv.find(keyword)
    55          portkey = getIpServiceKey(proto, port)
    56          if not svc:
    57              serviceKeys = (keyword, portkey)
    58              svc = IpServiceClass(keyword, serviceKeys=serviceKeys,
    59                                 description=descr, port=port)
    60              if port < 1024:
    61                  self.privserv.serviceclasses._setObject(svc.id, svc)
    62              else:
    63                  self.regserv.serviceclasses._setObject(svc.id, svc)
    64              self.log.info("Added IpServiceClass %s" % keyword)
    65          else:
    66              svc.addServiceKey(portkey)
    67
    68
    69  if __name__ == "__main__":
    70      loader = IpServiceLoader()
    71      loader.loadDatabase()
    72      print "Database Load is finished!"
    73