1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""StatusMonitor
15
16 Base class for makeing deamon programs
17
18 $Id: StatusMonitor.py,v 1.9 2003/08/29 20:33:10 edahl Exp $"""
19
20 __version__ = "$Revision: 1.9 $"[11:-2]
21
22 import signal
23 import os
24 import sys
25 import socket
26 import time
27
28 from Products.ZenUtils.ZenDaemon import ZenDaemon
29
31
33 ZenDaemon.__init__(self)
34 self.dnstries = 3
35 self.forwarddnscache = {}
36 self.reversednscache = {}
37
38
50
51
63
64
66 """try dns lookup dnstries times"""
67 ip = None
68 i=0
69 while 1:
70 try:
71 i+=1
72 ip = function(target)
73 except socket.error:
74 if i > self.getDnsTries():
75 raise
76 if ip: break
77 return ip
78
79
81 if not hasattr(self, 'dnstries'):
82 self.dnstries=3
83 return self.dnstries
84
85
87 """handle errors when loading config from server
88 we try configtries times if no previous config is found"""
89 for i in range(self.options.configtries):
90 try:
91 self.loadConfig()
92 return
93 except SystemExit: raise
94 except:
95 if self.validConfig():
96 self.log.exception(
97 "configuration load exception using previous configuration")
98 return
99 else:
100 self.log.exception('config load failed')
101 if i <= (self.options.configtries - 2):
102 self.log.warn(
103 "initial config load failed will retry")
104 time.sleep(self.options.configsleep)
105 else:
106 self.log.critical(
107 "initial config load failed %d times exiting"
108 % self.options.configtries)
109 sys.exit(2)
110
111
113 ZenDaemon.buildOptions(self)
114 self.parser.add_option('-T', '--configtries',
115 dest='configtries',
116 default=5,
117 action="store",
118 help="How many times to retry config connection")
119 self.parser.add_option('-S', '--configsleep',
120 dest='configsleep',
121 default=20,
122 action="store",
123 help="How long to sleep between config connections")
124