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 import urllib
24 import string
25 import time
26
27 URL = 'http://update.zenoss.org/cgi-bin/version'
28
29 DAY_SECONDS = 60*60*24
30 HOUR_SECONDS = 60*60
31
33 if s is None: return s
34 v = Version.parse('Zenoss ' + s)
35 v.revision = None
36 return v
37
39
40 - def getUpdate(self, dmd, manual, product=None):
41 """
42 Send a GET request to dev.zenoss.org giving some parameters about this
43 Zenoss installation and getting back the version number for the
44 most recent product release. The product can be passed in the product
45 parameter, but if product is None then the code will attempt to
46 figure out which product is currently running and use that.
47 """
48 if not product:
49 product = dmd.getProductName()
50 available = None
51 args = {}
52 args['pr'] = product
53 args['sk'] = dmd.uuid or "NOT ACTIVATED"
54 args['ac'] = (manual and '0') or '1'
55 args['zv'] = dmd.About.getZenossVersion().long()
56 args['pv'] = dmd.About.getPythonVersion().long()
57 args['mv'] = dmd.About.getMySQLVersion().long()
58 args['os'] = dmd.About.getOSVersion().long()
59 args['osv'] = dmd.About.getOSVersion().full()
60
61 args['rv'] = 'bad bad bad'
62 args['up'] = time.time() - dmd.getPhysicalRoot().Control_Panel.process_start
63
64
65
66 if not manual and dmd.reportMetricsOptIn:
67 args['nd'] = dmd.Devices.countDevices()
68 args['nu'] = len(dmd.ZenUsers.objectIds())
69 args['nm'] = dmd.Events.countInstances()
70 args['ne'] = dmd.ZenEventManager.countEventsSince(
71 time.time() - 24 * 60 * 60)
72 numProducts = 0
73 manufacturers = dmd.Manufacturers.objectValues(spec='Manufacturer')
74 for m in manufacturers:
75 numProducts += m.products.countObjects()
76 args['np'] = numProducts
77 args['nr'] = dmd.Reports.countReports()
78 args['nt'] = dmd.Devices.rrdTemplates.countObjects()
79 args['ns'] = dmd.Systems.countChildren()
80 args['ng'] = dmd.Groups.countChildren()
81 args['nl'] = dmd.Locations.countChildren()
82
83 query = urllib.urlencode(args.items())
84 for line in urllib.urlopen(URL + '?' + query):
85
86 if line.strip() and line[0] not in '<' + string.whitespace:
87 try:
88 available = parseVersion(line.strip())
89 break
90 except ValueError:
91 pass
92 return available
93
94 - def check(self, dmd, zem, manual=False):
128
129 if __name__ == "__main__":
130 from Products.ZenUtils import ZCmdBase
131 - class zendmd(ZCmdBase.ZCmdBase):
133 zendmd = zendmd()
134 uc = UpdateCheck()
135 uc.getUpdate = lambda *unused: parseVersion('0.24.0')
136 uc.check(zendmd.dmd, zendmd.dmd.ZenEventManager, manual=True)
137 transaction.commit()
138