def direct_post(dmd): callhome = CallHome(dmd) chs = CallHomeStatus() if not callhome.attempt('directpost'): return payload = callhome.get_payload() if not payload: logger.warning('Error getting or encrypting payload for direct-post') return payload = base64.urlsafe_b64encode(payload) params = urlencode({'enc': payload}) chs.stage(chs.REQUEST_CALLHOME) try: httpreq = urllib2.urlopen(POST_CHECKIN_URL, params, _URL_TIMEOUT) returnPayload = httpreq.read() except Exception as e: chs.stage(chs.REQUEST_CALLHOME, "FAILED", str(e)) logger.warning('Error retrieving data from callhome server %s', e) else: chs.stage(chs.REQUEST_CALLHOME, "FINISHED") callhome.save_return_payload(returnPayload) return
def render(self): dmd = self.context.dmd # if not logged in, inject nothing if not dmd.ZenUsers.getUserSettings(): return '' callhome = CallHome(dmd) # if we've checked in or attempted to check in recently, inject nothing if not callhome.attempt('browserjs'): return '' payload = callhome.get_payload(method='browserjs') if not payload: logger.warning('Error getting or encrypting payload for browserjs') return '' # Output the checkin data to a js snippet, wait a few seconds in the # browser, and inject script tags to the checkin url to the body tag. # This makes sure that the browser never waits on the checkin url. # Callbacks from the server script invoke the next # Zenoss.Callhome_next() return """<script type="text/javascript"> var packets = %s, currentPacket = 0; Zenoss.Callhome_next = function() { if (currentPacket < packets.length) { var script = document.createElement('script'); script.type= 'text/javascript'; script.src = "%s?enc=" + packets[currentPacket]; document.body.appendChild(script); } currentPacket += 1; }; var task = new Ext.util.DelayedTask(Zenoss.Callhome_next); task.delay(5000); </script>""" % (json.dumps(encode_for_js(payload)), JS_CALLHOME_URL)
def render(self): dmd = self.context.dmd # if not logged in, inject nothing if not dmd.ZenUsers.getUserSettings(): return '' callhome = CallHome(dmd) # if we've checked in or attempted to check in recently, inject nothing if not callhome.attempt('browserjs'): return '' payload = callhome.get_payload(method='browserjs') if not payload: logger.warning('Error getting or encrypting payload for browserjs') return '' # Output the checkin data to a js snippet, wait a few seconds in the # browser, and inject script tags to the checkin url to the body tag. # This makes sure that the browser never waits on the checkin url. # Callbacks from the server script invoke the next # Zenoss.Callhome_next() return """<script type="text/javascript"> var packets = %s, currentPacket = 0; Zenoss.Callhome_next = function() { if (currentPacket < packets.length) { var script = document.createElement('script'); script.type= 'text/javascript'; script.src = "%s?enc=" + packets[currentPacket]; document.body.appendChild(script); } currentPacket += 1; }; var task = new Ext.util.DelayedTask(Zenoss.Callhome_next); task.delay(5000); </script>""" % (json.dumps( encode_for_js(payload)), JS_CALLHOME_URL)