Exemplo n.º 1
0
 def post(self,*args,**kwargs):
     alert_type = self.get_argument("alert_type",None)
     begin_day = self.get_argument("begin_day",utils.get_currdate())
     end_day = self.get_argument("end_day",utils.get_currdate())
     begin_time = utils.datetime2msec("%s 00:00:00"%begin_day)
     end_time = utils.datetime2msec("%s 23:59:59"%end_day)
     query = self.mongodb.query_alert(alert_type,begin_time,end_time)
     page_data = self.get_mdb_page_data(query)
     self.render("alerts.html",page_data=page_data,**self.get_params())
Exemplo n.º 2
0
    def get(self):
        node_id = self.get_argument('node_id', None)
        day_code = self.get_argument('day_code', None)
        opr_nodes = self.get_opr_nodes()
        if not day_code:
            day_code = utils.get_currdate()
        begin = datetime.datetime.strptime("%s 00:00:00" % day_code,
                                           "%Y-%m-%d %H:%M:%S")
        end = datetime.datetime.strptime("%s 23:59:59" % day_code,
                                         "%Y-%m-%d %H:%M:%S")
        begin_time, end_time = time.mktime(begin.timetuple()), time.mktime(
            end.timetuple())
        _query = self.db.query(models.TrOnlineStat)

        if node_id:
            _query = _query.filter(models.TrOnlineStat.node_id == node_id)
        else:
            _query = _query.filter(
                models.TrOnlineStat.node_id.in_([i.id for i in opr_nodes]))

        _query = _query.filter(
            models.TrOnlineStat.stat_time >= begin_time,
            models.TrOnlineStat.stat_time <= end_time,
        )
        _data = [(q.stat_time * 1000, q.total) for q in _query]
        self.render_json(code=0, data=[{'data': _data}])
Exemplo n.º 3
0
    def get(self):
        node_id = self.get_argument('node_id',None)
        day_code = self.get_argument('day_code',None)
        opr_nodes = self.get_opr_nodes()
        if not day_code:
            day_code = utils.get_currdate()
        begin = datetime.datetime.strptime("%s 00:00:00" % day_code, "%Y-%m-%d %H:%M:%S")
        end = datetime.datetime.strptime("%s 23:59:59" % day_code, "%Y-%m-%d %H:%M:%S")
        begin_time, end_time = time.mktime(begin.timetuple()), time.mktime(end.timetuple())
        _query = self.db.query(models.TrFlowStat)

        if node_id:
            _query = _query.filter(models.TrFlowStat.node_id == node_id)
        else:
            _query = _query.filter(models.TrFlowStat.node_id.in_([i.id for i in opr_nodes]))

        _query = _query.filter(
            models.TrFlowStat.stat_time >= begin_time,
            models.TrFlowStat.stat_time <= end_time,
        )

        in_data = {"name": u"上行流量", "data": []}
        out_data = {"name": u"下行流量", "data": []}

        for q in _query:
            _stat_time = q.stat_time * 1000
            in_data['data'].append([_stat_time, float(utils.kb2mb(q.input_total))])
            out_data['data'].append([_stat_time, float(utils.kb2mb(q.output_total))])

        self.render_json(code=0, data=[in_data, out_data])
Exemplo n.º 4
0
 def get_notify_interval(self):
     try:
         notify_interval = int(self.get_param_value("expire_notify_interval",1440)) * 60.0
         notify_time = self.get_param_value("expire_notify_time", None)
         if notify_time:
             _now_hm = datetime.datetime.now().strftime("%H:%M")
             _ymd = utils.get_currdate()
             if _now_hm  > notify_time:
                 _ymd = (datetime.datetime.now() + datetime.timedelta(days=1)).strftime("%Y-%m-%d") 
             _now = datetime.datetime.now()
             _interval = datetime.datetime.strptime("%s %s"%(_ymd,notify_time),"%Y-%m-%d %H:%M") -_now
             notify_interval = int(_interval.total_seconds())
         return abs(notify_interval)
     except:
         return 120
Exemplo n.º 5
0
 def get_notify_interval(self):
     try:
         notify_interval = int(
             self.get_param_value("expire_notify_interval", 1440)) * 60.0
         notify_time = self.get_param_value("expire_notify_time", None)
         if notify_time:
             _now_hm = datetime.datetime.now().strftime("%H:%M")
             _ymd = utils.get_currdate()
             if _now_hm > notify_time:
                 _ymd = (datetime.datetime.now() +
                         datetime.timedelta(days=1)).strftime("%Y-%m-%d")
             _now = datetime.datetime.now()
             _interval = datetime.datetime.strptime(
                 "%s %s" % (_ymd, notify_time), "%Y-%m-%d %H:%M") - _now
             notify_interval = int(_interval.total_seconds())
         return abs(notify_interval)
     except:
         return 120
Exemplo n.º 6
0
 def post(self, template_variables={}):
     day_code = self.get_argument("day_code", utils.get_currdate())
     begin_time = utils.datetime2msec("%s 00:00:00" % day_code)
     end_time = utils.datetime2msec("%s 23:59:59" % day_code)
     logger.info("query perfdata %s -- %s" % (begin_time, end_time))
     group_name = self.get_argument("group_name", None)
     groups = self.nagapi.list_hostgroup()
     all_hosts = self.nagapi.list_host(group_name)
     host_name = self.get_argument("host_name", None)
     host = self.nagapi.get_host(host_name)
     self.render("host_perf.html",
                 groups=groups,
                 group_name=group_name,
                 host_name=host_name,
                 host=host,
                 day_code=day_code,
                 begin_time=begin_time,
                 end_time=end_time,
                 STATUS=STATUS,
                 STYLE=STYLE)
Exemplo n.º 7
0
 def post(self, template_variables={}):
     day_code = self.get_argument("day_code",utils.get_currdate())
     begin_time = utils.datetime2msec("%s 00:00:00"%day_code)
     end_time = utils.datetime2msec("%s 23:59:59"%day_code)
     logger.info("query perfdata %s -- %s"%(begin_time,end_time))
     group_name = self.get_argument("group_name",None)
     groups = self.nagapi.list_hostgroup()
     all_hosts = self.nagapi.list_host(group_name)
     host_name = self.get_argument("host_name",None)
     host = self.nagapi.get_host(host_name)
     self.render("host_perf.html",
         groups=groups,
         group_name=group_name,
         host_name=host_name,
         host=host,
         day_code=day_code,
         begin_time=begin_time, 
         end_time=end_time,
         STATUS=STATUS,
         STYLE=STYLE
     )
Exemplo n.º 8
0
    def get(self):
        node_id = self.get_argument('node_id',None)
        day_code = self.get_argument('day_code',None)
        opr_nodes = self.get_opr_nodes()
        if not day_code:
            day_code = utils.get_currdate()
        begin = datetime.datetime.strptime("%s 00:00:00" % day_code, "%Y-%m-%d %H:%M:%S")
        end = datetime.datetime.strptime("%s 23:59:59" % day_code, "%Y-%m-%d %H:%M:%S")
        begin_time, end_time = time.mktime(begin.timetuple()), time.mktime(end.timetuple())
        _query = self.db.query(models.TrOnlineStat)

        if node_id:
            _query = _query.filter(models.TrOnlineStat.node_id == node_id)
        else:
            _query = _query.filter(models.TrOnlineStat.node_id.in_([i.id for i in opr_nodes]))

        _query = _query.filter(
            models.TrOnlineStat.stat_time >= begin_time,
            models.TrOnlineStat.stat_time <= end_time,
        )
        _data = [(q.stat_time * 1000, q.total) for q in _query]
        self.render_json(code=0, data=[{'data': _data}])
Exemplo n.º 9
0
    def get(self):
        node_id = self.get_argument('node_id', None)
        day_code = self.get_argument('day_code', None)
        opr_nodes = self.get_opr_nodes()
        if not day_code:
            day_code = utils.get_currdate()
        begin = datetime.datetime.strptime("%s 00:00:00" % day_code,
                                           "%Y-%m-%d %H:%M:%S")
        end = datetime.datetime.strptime("%s 23:59:59" % day_code,
                                         "%Y-%m-%d %H:%M:%S")
        begin_time, end_time = time.mktime(begin.timetuple()), time.mktime(
            end.timetuple())
        _query = self.db.query(models.TrFlowStat)

        if node_id:
            _query = _query.filter(models.TrFlowStat.node_id == node_id)
        else:
            _query = _query.filter(
                models.TrFlowStat.node_id.in_([i.id for i in opr_nodes]))

        _query = _query.filter(
            models.TrFlowStat.stat_time >= begin_time,
            models.TrFlowStat.stat_time <= end_time,
        )

        in_data = {"name": u"上行流量", "data": []}
        out_data = {"name": u"下行流量", "data": []}

        for q in _query:
            _stat_time = q.stat_time * 1000
            in_data['data'].append(
                [_stat_time, float(utils.kb2mb(q.input_total))])
            out_data['data'].append(
                [_stat_time, float(utils.kb2mb(q.output_total))])

        self.render_json(code=0, data=[in_data, out_data])
Exemplo n.º 10
0
 def get_expire_date(self, expire):
     if utils.is_expire(expire):
         return utils.get_currdate()
     else:
         return expire