def server_status(self, serverid): "Display server status" server = self._get_server(serverid) if not server: abort(404) totals = DailyTotals(Session, c.user) mailq = MailQueue(Session, c.user) totals = totals.get(server.hostname) inbound = mailq.get(1, server.hostname)[0] outbound = mailq.get(2, server.hostname)[0] statusdict = dict(total=totals.total, mta=0, scanners=0, av=0, clean_mail=totals.clean, high_spam=totals.highspam, virii=totals.virii, spam_mail=totals.lowspam, inq=inbound, outq=outbound, otherinfected=totals.infected, uptime='Unknown', time=None, load=(0, 0, 0), mem=dict(free=0, used=0, total=0, percent=0), partitions=[], net={}, cpu=0) try: task = systemstatus.apply_async(routing_key=server.hostname) task.wait(30) hoststatus = task.result statusdict.update(hoststatus) info = HOSTSTATUS_MSG % dict(n=server.hostname) audit_log(c.user.username, 1, unicode(info), request.host, request.remote_addr, arrow.utcnow().datetime) except (TimeoutError, QueueNotFound): pass jsondata = [ dict(tooltip=LABELS[attr], y=getattr(totals, attr), stroke='black', color=PIE_COLORS[attr]) for attr in ['clean', 'highspam', 'lowspam', 'virii', 'infected'] if getattr(totals, attr) ] c.chart_data = json.dumps(jsondata) c.server = server c.status = statusdict return self.render('/status/serverstatus.html')
def server_status(self, serverid): "Display server status" server = self._get_server(serverid) if not server: abort(404) totals = DailyTotals(Session, c.user) mailq = MailQueue(Session, c.user) totals = totals.get(server.hostname) inbound = mailq.get(1, server.hostname)[0] outbound = mailq.get(2, server.hostname)[0] statusdict = dict(total=totals.total, mta=0, scanners=0, av=0, clean_mail=totals.clean, high_spam=totals.highspam, virii=totals.virii, spam_mail=totals.lowspam, inq=inbound, outq=outbound, otherinfected=totals.infected, uptime='Unknown', time=None, load=(0, 0, 0), mem=dict(free=0, used=0, total=0, percent=0), partitions=[], net={}, cpu=0) try: task = systemstatus.apply_async(routing_key=server.hostname) task.wait(30) hoststatus = task.result statusdict.update(hoststatus) info = HOSTSTATUS_MSG % dict(n=server.hostname) audit_log(c.user.username, 1, unicode(info), request.host, request.remote_addr, arrow.utcnow().datetime) except (TimeoutError, QueueNotFound): pass jsondata = [dict(tooltip=LABELS[attr], y=getattr(totals, attr), stroke='black', color=PIE_COLORS[attr]) for attr in ['clean', 'highspam', 'lowspam', 'virii', 'infected'] if getattr(totals, attr)] c.chart_data = json.dumps(jsondata) c.server = server c.status = statusdict return self.render('/status/serverstatus.html')
def server_status(self, serverid): "Display server status" server = self._get_server(serverid) if not server: abort(404) totals = DailyTotals(Session, c.user) mailq = MailQueue(Session, c.user) totals = totals.get(server.hostname) inbound = mailq.get(1, server.hostname)[0] outbound = mailq.get(2, server.hostname)[0] statusdict = dict(total=totals.total, mta=0, scanners=0, av=0, clean_mail=totals.clean, high_spam=totals.highspam, virii=totals.virii, spam_mail=totals.lowspam, inq=inbound, outq=outbound, otherinfected=totals.infected, uptime='Unknown', time=None, load=(0, 0, 0), mem=dict(free=0, used=0, total=0, percent=0), partitions=[], net={}, cpu=0) try: task = systemstatus.apply_async(queue=server.hostname) task.wait(30) hoststatus = task.result statusdict.update(hoststatus) info = HOSTSTATUS_MSG % dict(n=server.hostname) audit_log(c.user.username, 1, info, request.host, request.remote_addr, now()) except (TimeoutError, QueueNotFound): pass c.server = server c.status = statusdict return render('/status/serverstatus.html')
def server_status(self, serverid): "Display server status" server = self._get_server(serverid) if not server: abort(404) totals = DailyTotals(Session, c.user) mailq = MailQueue(Session, c.user) totals = totals.get(server.hostname) inbound = mailq.get(1, server.hostname)[0] outbound = mailq.get(2, server.hostname)[0] statusdict = dict(total=totals.total, mta=0, scanners=0, av=0, clean_mail=totals.clean, high_spam=totals.highspam, virii=totals.virii, spam_mail=totals.lowspam, inq=inbound, outq=outbound, otherinfected=totals.infected, uptime='Unknown', load=(0, 0, 0), mem=dict(free=0, used=0, total=0, percent=0), partitions=[], net={}, cpu=0) try: task = systemstatus.apply_async(queue=server.hostname) task.wait(30) hoststatus = task.result statusdict.update(hoststatus) info = HOSTSTATUS_MSG % dict(n=server.hostname) audit_log(c.user.username, 1, info, request.host, request.remote_addr, datetime.now()) except (TimeoutError, QueueNotFound): pass c.server = server c.status = statusdict return render('/status/serverstatus.html')
def host_status(hostname): "Check host status" try: task = systemstatus.apply_async(routing_key=hostname) task.wait(30) hoststatus = task.result except (TimeoutError, QueueNotFound): return False # check load if hoststatus['load'][0] > 15: return False # return quick if any service is not running for service in ['mta', 'scanners', 'av']: if hoststatus[service] == 0: return False # check disks for part in hoststatus['partitions']: if part['percent'] >= 95: return False return True