def transform_callback(self, data): for transform in data.transforms: key = transform.header.frame_id + '->' + transform.child_frame_id if key not in self.state: self.state[key] = {'lastseen': 0} self.state[key]['lastseen'] = time.time() if time.time() - self.last_update > 0.5: sendstate({'transforms': self.state}) self.last_update = time.time()
def timercallback(self, event): try: self.update_topictypes() sendstate({'topictypes': self.topictypes}) self.update_pubsubs() sendstate({ 'nodes': self.nodes, 'topics': self.topics, 'subscriptions': self.subscriptions, 'publications': self.publications, }) except Exception, e: logging.error(e) return
def retreive_services(self): services_str = " ".join(services) try: statusnr_enabled, output_enabled = self.ssh.run_command( "systemctl is-enabled " + services_str) statusnr_active, output_active = self.ssh.run_command( "systemctl is-active " + services_str) except Exception, e: out = [] for s in services: out.append( SystemdService(name=s, running=SystemdServiceRunning.ERROR, statustext=str(e), enabled=SystemdServiceEnabled.ERROR, lastupdate=time.time())) sendstate({'systemdservices': out}) return
def status_callback(self, status): if not self.statuscallback_first: if not self.recording.is_recording and status.recordingactive: add_logline( time.time(), "`Recording started, filename: %s`" % status.filename) if self.recording.is_recording and not status.recordingactive: add_logline( time.time(), "`Recording stopped after %s seconds.`" % self.recording.recording_duration) self.recording.is_recording = status.recordingactive self.recording.recording_file = status.filename self.recording.recording_duration = status.duration self.recording.recording_filesize = status.filesize self.recording.recording_topics = status.topics self.recording.lastrefresh_recording = time.time() self.statuscallback_first = False sendstate({'recording': self.recording})
def set_rosnode_health(self, up): sendstate({'rosnode_up': up})
def pings_callback(self, result): print result sendstate({'pings': {result.ip: {'ip': result.ip, 'friendlyname': result.friendlyname, 'success': result.success}}})
def ping(self): success = os.system("ping -c 1 -w 1 -W 1 %s > /dev/null 2>&1" % self.host) == 0 sendstate({'ping': Ping(time.time(), success)})
statusnr_active, output_active = self.ssh.run_command( "systemctl is-active " + services_str) except Exception, e: out = [] for s in services: out.append( SystemdService(name=s, running=SystemdServiceRunning.ERROR, statustext=str(e), enabled=SystemdServiceEnabled.ERROR, lastupdate=time.time())) sendstate({'systemdservices': out}) return services_active = output_active.split("\n") services_enabled = output_enabled.split("\n") out = [] for i in range(len(services)): out.append( SystemdService(name=services[i], lastupdate=time.time(), running=SystemdServiceRunning.fromstring( services_active[i]), enabled=SystemdServiceEnabled.fromstring( services_enabled[i]), statustext="active: " + services_active[i] + "\n" + "enabled: " + services_enabled[i])) sendstate({'systemdservices': out})
% str(e)) time.sleep(1.25) def ping(self): try: self.client.ensure_transport() # This file contains two numbers: the uptime of the system (seconds), # and the amount of time spent in idle process (seconds). (exitcode, proc_uptime) = self.client.run_command("cat /proc/uptime") if exitcode != 0: raise Exception("uptime exit code was not 0") connected = True uptime_seconds = float(proc_uptime.strip().split(" ")[0]) if self.last_upstime_seconds > uptime_seconds: add_logline(time.time(), "`Luke powercycled`") self.last_upstime_seconds = uptime_seconds uptimestr = time.strftime("%Hh %Mm %Ss", time.gmtime(uptime_seconds)) except Exception, e: uptimestr = str(e) connected = False sendstate({ 'ssh': { 'connected': connected, 'uptime': uptimestr, 'lastping': time.time() } })
def statistics_callback(self, statisticsmessage): for topicstats in statisticsmessage.statistics: self.update_statistics(topicstats) sendstate({'topics': self.topics})
def config_callback(self, config): self.recording.config_topics = config.topics self.recording.config_filename = config.filename self.recording.lastrefresh_config = time.time() sendstate({'recording': self.recording})