def graphs(request): gset = request.GET.get("gset", None) gsets = events.raiseDictEvent("GetGraphSets") if gset not in gsets: raise NotFound(_("Unknown graphic set")) searchq = request.GET.get("searchquery", None) period = request.GET.get("period", "day") tplvars = dict(graphs={}, period=period) domain = check_domain_access(request.user, searchq) if domain is None: return render_to_json_response({}) tplvars["domain"] = domain if period == "custom": if "start" not in request.GET or "end" not in request.GET: raise BadRequest(_("Bad custom period")) start = request.GET["start"] end = request.GET["end"] expr = re.compile(r'[:\- ]') period_name = "%s_%s" % (expr.sub('', start), expr.sub('', end)) start = date_to_timestamp(expr.split(start)) end = date_to_timestamp(expr.split(end)) else: end = int(time.mktime(time.localtime())) start = "-1%s" % period period_name = period tplvars['graphs'] = gsets[gset].export(tplvars["domain"], start, end) tplvars["period_name"] = period_name tplvars["start"] = start tplvars["end"] = end return render_to_json_response(tplvars)
def graphs(request): gset = request.GET.get("gset", None) gsets = events.raiseDictEvent("GetGraphSets") if not gset in gsets: raise NotFound(_("Unknown graphic set")) searchq = request.GET.get("searchquery", None) period = request.GET.get("period", "day") tplvars = dict(graphs={}, period=period) if searchq in [None, "global"]: if not request.user.is_superuser: if not Domain.objects.get_for_admin(request.user).count(): return render_to_json_response({}) tplvars.update( domain=Domain.objects.get_for_admin(request.user)[0].name ) else: tplvars.update(domain="global") else: domain = Domain.objects.filter(name__contains=searchq) if domain.count() != 1: return render_to_json_response({}) if not request.user.can_access(domain[0]): raise PermDeniedException tplvars.update(domain=domain[0].name) if period == "custom": if not "start" in request.GET or not "end" in request.GET: raise BadRequest(_("Bad custom period")) start = request.GET["start"] end = request.GET["end"] expr = re.compile(r'[:\- ]') period_name = "%s_%s" % (expr.sub('', start), expr.sub('', end)) start = date_to_timestamp(expr.split(start)) end = date_to_timestamp(expr.split(end)) else: end = int(time.mktime(time.localtime())) start = "-1%s" % period period_name = period tplvars['graphs'] = gsets[gset].export(tplvars["domain"], start, end) tplvars["period_name"] = period_name tplvars["start"] = start tplvars["end"] = end return render_to_json_response(tplvars)
def graphs(request): gset = request.GET.get("gset", None) gsets = events.raiseDictEvent("GetGraphSets") if not gset in gsets: raise NotFound(_("Unknown graphic set")) searchq = request.GET.get("searchquery", None) period = request.GET.get("period", "day") tplvars = dict(graphs={}, period=period) if searchq in [None, "global"]: if not request.user.is_superuser: if not Domain.objects.get_for_admin(request.user).count(): return render_to_json_response({}) tplvars.update( domain=Domain.objects.get_for_admin(request.user)[0].name) else: tplvars.update(domain="global") else: domain = Domain.objects.filter(name__contains=searchq) if domain.count() != 1: return render_to_json_response({}) if not request.user.can_access(domain[0]): raise PermDeniedException tplvars.update(domain=domain[0].name) if period == "custom": if not "start" in request.GET or not "end" in request.GET: raise BadRequest(_("Bad custom period")) start = request.GET["start"] end = request.GET["end"] expr = re.compile(r'[:\- ]') period_name = "%s_%s" % (expr.sub('', start), expr.sub('', end)) start = date_to_timestamp(expr.split(start)) end = date_to_timestamp(expr.split(end)) else: end = int(time.mktime(time.localtime())) start = "-1%s" % period period_name = period tplvars['graphs'] = gsets[gset].export(tplvars["domain"], start, end) tplvars["period_name"] = period_name tplvars["start"] = start tplvars["end"] = end return render_to_json_response(tplvars)
def _parse_date(self, line): """Try to match a date inside :kw:`line` and to convert it to a timestamp. We try different date format until we find valid one. We then store it for future use. :param str line: a log entry :return: the remaining part of the line or None """ match = None if self.date_expr is None: for expr in [self._s_date_expr, self._hp_date_expr]: match = expr.match(line) if match is not None: self.date_expr = expr break else: match = self.date_expr.match(line) if match is None: return None ho = match.group("hour") mi = match.group("min") se = match.group("sec") se = int(int(se) / rrdstep) # rrd step is one-minute => se = 0 if self._prev_se != se or self._prev_mi != mi or self._prev_ho != ho: mo = match.group("month") da = match.group("day") try: ye = match.group("year") except IndexError: ye = self.year(mo) self.cur_t = date_to_timestamp([ye, mo, da, ho, mi, se]) self.cur_t = self.cur_t - self.cur_t % rrdstep self._prev_mi = mi self._prev_ho = ho self._prev_se = se return match.group('eol')