1
2
3
4
5
6
7
8
9
10
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
26
27 from Products.ZenUtils.BasicLoader import BasicLoader
28
29 from Products.ZenModel.IpService import getIpServiceKey
30 from Products.ZenModel.IpServiceClass import IpServiceClass
31
33
34 lineparse = re.compile(r"^(\S+)\s+(\d+)/(\S+)(.*)")
35
36
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