def dict(self): d = { 'pid': self.pid, 'name': self.name, 'status': self.status, 'status_color': self.status_color, 'first_seen': netarray.timestamp(self.first_seen), 'last_seen': netarray.timestamp(self.last_seen) } if self.addr != None: d['addr'] = self.addr d['port'] = self.port return d
def tty_out(self): t = netarray.timestamp(self.last_seen, fmt='short') t = rpad(t, 15) dt = utcnow() - self.last_seen if dt < timedelta(minutes=1): t = colorize(t, color='green') if timedelta(minutes=1) < dt < timedelta(minutes=5): t = colorize(t, color='yellow') if dt > timedelta(minutes=5): t = colorize(t, color='red') name = colorize(self.name, 'cyan') pid = str(self.pid) if self.addr != None: _addr, _port = self.addr, self.port else: _addr, _port = 'unknown host', '' addr = colorize('%s:%s' % (_addr, _port), 'magenta') status = '[%s]' % cpad(self.status, 8) status = colorize(status, self.status_color) b0 = rpad('%s@%s(pid %s) ' % (name, addr, pid), 57) b1 = t b2 = status return ''.join((b0, b1, b2))
def tty_out(self): t = netarray.timestamp(self.systime, fmt='short') out = colorize('snapshot %s\n' % t, 'cyan') for e in self.names.values(): out += indent(e.tty_out()) + '\n' return out
def dict(self): d = { 'systime': netarray.timestamp(self.systime), 'status': self.status, 'pid': self.pid, 'addr': self.addr, 'port': self.port, 'name': self.name, 'status_color': self.status_color, 'event': 'pulse' } return d
def serialize(self): # test for empty snapshot if self.systime == None: return json.dumps({'event': 'null_snapshot'}) t = netarray.timestamp(self.systime) entries = [] if len(self.names) > 0: entries = [e.serialize() for e in self.names.values()] d = {'event': 'snapshot', 'systime': t, 'entries': entries} return json.dumps(d)