def _status_log(request): """ Helper function to any status view that requires log access """ c = {} c['messages'] = [] c['errors'] = [] start_time = request.GET.get('start_time', '') end_time = request.GET.get('end_time', '') host_name = request.GET.get('host_name', '') service_description = request.GET.get('service_description', '') limit = request.GET.get('limit', '') if end_time == '': end_time = None else: end_time = float(end_time) if start_time == '': now = time.time() seconds_in_a_day = 60 * 60 * 24 seconds_today = now % seconds_in_a_day # midnight of today start_time = now - seconds_today else: start_time = float(start_time) if limit == '': limit = 2000 else: limit = int(limit) # Any querystring parameters we will treat as a search string to get_log_entries, but we need to massage them # a little bit first kwargs = {} for k, v in list(request.GET.items()): if k == 'search': k = 'search' elif k in ('start_time', 'end_time', 'start_time_picker', 'end_time_picker', 'limit', 'start_hours', 'end_hours'): continue elif v is None or len(v) == 0: continue k = str(k) v = str(v) kwargs[k] = v c['log'] = utils.get_log_entries(request, start_time=start_time, end_time=end_time, **kwargs)[-limit:] c['log'].reverse() c['logs'] = {'all': []} for line in c['log']: if line['class_name'] not in list(c['logs'].keys()): c['logs'][line['class_name']] = [] c['logs'][line['class_name']].append(line) c['logs']['all'].append(line) c['start_time'] = start_time c['end_time'] = end_time return c
def _status_log(request): """ Helper function to any status view that requires log access """ c = {} c['messages'] = [] c['errors'] = [] start_time = request.GET.get('start_time', '') end_time = request.GET.get('end_time', '') host_name = request.GET.get('host_name', '') service_description = request.GET.get('service_description', '') limit = request.GET.get('limit', '') if end_time == '': end_time = None else: end_time = float(end_time) if start_time == '': now = time.time() seconds_in_a_day = 60 * 60 * 24 seconds_today = now % seconds_in_a_day # midnight of today start_time = now - seconds_today else: start_time = float(start_time) if limit == '': limit = 2000 else: limit = int(limit) # Any querystring parameters we will treat as a search string to get_log_entries, but we need to massage them # a little bit first kwargs = {} for k, v in request.GET.items(): if k == 'search': k = 'search' elif k in ( 'start_time', 'end_time', 'start_time_picker', 'end_time_picker', 'limit', 'start_hours', 'end_hours'): continue elif v is None or len(v) == 0: continue k = str(k) v = str(v) kwargs[k] = v c['log'] = utils.get_log_entries( request, start_time=start_time, end_time=end_time, **kwargs)[-limit:] c['log'].reverse() c['logs'] = {'all': []} for line in c['log']: if line['class_name'] not in c['logs'].keys(): c['logs'][line['class_name']] = [] c['logs'][line['class_name']].append(line) c['logs']['all'].append(line) c['start_time'] = start_time c['end_time'] = end_time return c
def contact_detail(request, contact_name): """ Detailed information for one specific contact """ c = {} c['messages'] = [] c['errors'] = [] c['contact_name'] = contact_name l = adagios.status.utils.livestatus(request) backend = request.GET.get('backend', None) # Fetch contact and basic information try: contact = l.get_contact(contact_name, backend) c['contact'] = contact except IndexError: raise Exception("Contact named '%s' was not found." % contact_name) # Active comments c['comments'] = l.query( 'GET comments', 'Filter: comment ~ %s' % contact_name, ) for i in c['comments']: if i.get('type') == 1: i['state'] = i['host_state'] else: i['state'] = i['service_state'] # Services this contact can see c['services'] = l.query('GET services', "Filter: contacts >= %s" % contact_name) # Activity log c['log'] = utils.get_log_entries(request, search=str(contact_name)) # Contact groups c['groups'] = l.query('GET contactgroups', 'Filter: members >= %s' % contact_name) # Git audit logs nagiosdir = dirname(adagios.settings.nagios_config or pynag.Model.config.guess_cfg_file()) git = pynag.Utils.GitRepo(directory=nagiosdir) c['gitlog'] = git.log(author_name=contact_name) return render_to_response('status_contact.html', c, context_instance=RequestContext(request))
def contact_detail(request, contact_name): """ Detailed information for one specific contact """ c = {} c['messages'] = [] c['errors'] = [] c['contact_name'] = contact_name l = adagios.status.utils.livestatus(request) backend = request.GET.get('backend', None) # Fetch contact and basic information try: contact = l.get_contact(contact_name, backend) c['contact'] = contact except IndexError: raise Exception("Contact named '%s' was not found." % contact_name) # Active comments c['comments'] = l.query( 'GET comments', 'Filter: comment ~ %s' % contact_name,) for i in c['comments']: if i.get('type') == 1: i['state'] = i['host_state'] else: i['state'] = i['service_state'] # Services this contact can see c['services'] = l.query( 'GET services', "Filter: contacts >= %s" % contact_name) # Activity log c['log'] = utils.get_log_entries(request, search=str(contact_name)) # Contact groups c['groups'] = l.query( 'GET contactgroups', 'Filter: members >= %s' % contact_name) # Git audit logs nagiosdir = dirname(adagios.settings.nagios_config or pynag.Model.config.guess_cfg_file()) git = pynag.Utils.GitRepo(directory=nagiosdir) c['gitlog'] = git.log(author_name=contact_name) return render_to_response('status_contact.html', c, context_instance=RequestContext(request))