1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__='''UpdateCheck
15
16 '''
17
18 import Globals
19 import transaction
20 from Products.ZenUtils.Version import Version
21 from Products.ZenEvents import Event
22 from Products.ZenEvents.ZenEventClasses import Status_Update
23 from Products.Zuul import getFacade
24 from zenoss.protocols.services.zep import ZepConnectionError
25 import urllib
26 import string
27 import time
28 import logging
29
30 logger = logging.getLogger('zen.UpdateCheck')
31
32 URL = 'http://update.zenoss.org/cgi-bin/version'
33
34 DAY_SECONDS = 60*60*24
35 HOUR_SECONDS = 60*60
36
38 if s is None: return s
39 v = Version.parse('Zenoss ' + s)
40 v.revision = None
41 return v
42
44
45 - def getUpdate(self, dmd, manual, product=None):
46 """
47 Send a GET request to dev.zenoss.org giving some parameters about this
48 Zenoss installation and getting back the version number for the
49 most recent product release. The product can be passed in the product
50 parameter, but if product is None then the code will attempt to
51 figure out which product is currently running and use that.
52 """
53 if not product:
54 product = dmd.getProductName()
55 available = None
56 args = {}
57 args['pr'] = product
58 args['sk'] = dmd.uuid or "NOT ACTIVATED"
59 args['ac'] = (manual and '0') or '1'
60 args['zv'] = dmd.About.getZenossVersion().long()
61 args['pv'] = dmd.About.getPythonVersion().long()
62 args['mv'] = dmd.About.getMySQLVersion().long()
63 args['os'] = dmd.About.getOSVersion().long()
64 args['osv'] = dmd.About.getOSVersion().full()
65
66 args['rv'] = 'bad bad bad'
67 args['up'] = time.time() - dmd.getPhysicalRoot().Control_Panel.process_start
68
69
70
71 if not manual and dmd.reportMetricsOptIn:
72 args['nd'] = dmd.Devices.countDevices()
73 args['nu'] = len(dmd.ZenUsers.objectIds())
74 args['nm'] = dmd.Events.countInstances()
75
76 numEvents = 0
77 try:
78 zep = getFacade('zep')
79 numEvents = zep.countEventsSince(time.time() - 24 * 60 * 60)
80 except ZepConnectionError:
81 logger.warning("ZEP not running - failed to retrieve event count")
82
83 args['ne'] = numEvents
84
85 numProducts = 0
86 manufacturers = dmd.Manufacturers.objectValues(spec='Manufacturer')
87 for m in manufacturers:
88 numProducts += m.products.countObjects()
89 args['np'] = numProducts
90 args['nr'] = dmd.Reports.countReports()
91 args['nt'] = dmd.Devices.rrdTemplates.countObjects()
92 args['ns'] = dmd.Systems.countChildren()
93 args['ng'] = dmd.Groups.countChildren()
94 args['nl'] = dmd.Locations.countChildren()
95
96 query = urllib.urlencode(args.items())
97 for line in urllib.urlopen(URL + '?' + query):
98
99 if line.strip() and line[0] not in '<' + string.whitespace:
100 try:
101 available = parseVersion(line.strip())
102 break
103 except ValueError:
104 pass
105 return available
106
107 - def check(self, dmd, zem, manual=False):
141
142 if __name__ == "__main__":
143 from Products.ZenUtils import ZCmdBase
144 - class zendmd(ZCmdBase.ZCmdBase):
146 zendmd = zendmd()
147 uc = UpdateCheck()
148 uc.getUpdate = lambda *unused: parseVersion('0.24.0')
149 uc.check(zendmd.dmd, zendmd.dmd.ZenEventManager, manual=True)
150 transaction.commit()
151