def _GET(self, *param, **params): self.__template__.dir = "hostby1logby1appby1" self.__template__.file = "hostby1logby1appby1" self.__template__.media = "part" appname = param[1] filename = param[2] log_config = None if not validates_log(self): self.logger.debug("Get log failed. Did not validate.") return web.badrequest(self.view.alert) config = LogViewConfigParam(LOG_VIEW_XML_FILE) config.load_xml_config() app = config.findby1application(appname) for log in app["logs"]: if log["filename"] == filename: log_config = log lines = [] param_value = {} if is_param(self.input, "k"): param_value["k"] = self.input.k else: param_value["k"] = "" start_day = str2datetime(self.input.s, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0]) end_day = str2datetime(self.input.e, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0]) (start_hour, start_minute) = self.input.st.split(":", 2) (end_hour, end_minute) = self.input.et.split(":", 2) start_time = create_epochsec(start_day.year, start_day.month, start_day.day, int(start_hour), int(start_minute)) end_time = create_epochsec(end_day.year, end_day.month, end_day.day, int(end_hour), int(end_minute)) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest(_("Getting reports failed. Start time > end time.")) param_value["start_datetime"] = "%s %s" % (start_day.strftime("%Y/%m/%d"), self.input.st) param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et) if log_config["view_lotatelog"]: try: lines = read_log_with_lotate( filename, self.input.m, log_config, param_value["start_datetime"], param_value["end_datetime"], param_value["k"], ) if lines is False: return web.notfound() except Exception, e: self.logger.warning("log file open error: %s" % e)
def _GET(self, *param, **params): self.__template__.dir = "hostby1logby1appby1" self.__template__.file = "hostby1logby1appby1" self.__template__.media = "part" appname = param[1] log_config = None if not validates_log(self): self.logger.debug("Get log failed. Did not validate.") return web.badrequest(self.view.alert) config = LogViewConfigParam(LOG_VIEW_XML_FILE) config.load_xml_config() app = config.findby1application(appname) lines = [] param_value = {} if self.input.has_key("k"): param_value["k"] = self.input.k else: param_value["k"] = "" start_day = str2datetime(self.input.s, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) end_day = str2datetime(self.input.e, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) (start_hour, start_minute) = self.input.st.split(':', 2) (end_hour, end_minute) = self.input.et.split(':', 2) start_time = create_epochsec(start_day.year, start_day.month, start_day.day, int(start_hour), int(start_minute), ) end_time = create_epochsec(end_day.year, end_day.month, end_day.day, int(end_hour), int(end_minute), ) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest(_('Getting reports failed. Start time > end time.')) param_value["start_datetime"] = "%s %s" % (start_day.strftime("%Y/%m/%d"), self.input.st) param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et) lines = read_all_log(app, int(self.input.m), param_value["start_datetime"], param_value["end_datetime"], param_value["k"]) self.view.log_json = json_dumps(lines) return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() target = param[1] if target is None: return web.notfound() dev = param[2] if dev is None: return web.notfound() if not validates_report(self): self.logger.debug("Get report failed. Did not validate.") return web.badrequest(self.view.alert) today = datetime.datetime.today() if is_param(self.input, 'report_start_day') and not is_empty(self.input.report_start_day): start_day = str2datetime(self.input.report_start_day, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) else: start_day = today - datetime.timedelta(1) if is_param(self.input, 'report_start_time') and not is_empty(self.input.report_start_time): (start_hour, start_minute) = self.input.report_start_time.split(':',2) start_hour = int(start_hour) start_minute = int(start_minute) else: start_hour = today.hour start_minute = today.minute if is_param(self.input, 'report_end_day') and not is_empty(self.input.report_end_day): end_day = str2datetime(self.input.report_end_day, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) else: end_day = today if is_param(self.input, 'report_end_time') and not is_empty(self.input.report_end_time): (end_hour, end_minute) = self.input.report_end_time.split(':', 2) end_hour = int(end_hour) end_minute = int(end_minute) else: end_hour = today.hour end_minute = today.minute start_time = create_epochsec(start_day.year, start_day.month, start_day.day, start_hour, start_minute, ) end_time = create_epochsec(end_day.year, end_day.month, end_day.day, end_hour, end_minute, ) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest(_('Getting reports failed. Start time > end time.')) if is_param(self.input, 'type') and not is_empty(self.input.type): type = self.input.type else: type = "default" if is_param(self.input, 'host') and not is_empty(self.input.host): host = self.input.host else: host = None if is_param(self.input, 'libvirt_target') and not is_empty(self.input.libvirt_target): libvirt_target = self.input.libvirt_target else: libvirt_target = None rrd = RRD(self._, self.me.languages) if host is not None: if rrd.set_rrd_dir_host(host) is False: self.logger.debug("Get report failed. Target host not found.") return web.notfound() filepath = rrd.create_graph(target, dev, type, start_time, end_time, libvirt_target) if filepath != "": self.download.type = OUTPUT_TYPE_FILE self.download.file = filepath self.download.once = True return True
def _GET(self, *param, **params): self.__template__.dir = "hostby1logby1appby1" self.__template__.file = "hostby1logby1appby1" self.__template__.media = "part" appname = param[1] log_config = None if not validates_log(self): self.logger.debug("Get log failed. Did not validate.") return web.badrequest(self.view.alert) config = LogViewConfigParam(LOG_VIEW_XML_FILE) config.load_xml_config() app = config.findby1application(appname) lines = [] param_value = {} if self.input.has_key("k"): param_value["k"] = self.input.k else: param_value["k"] = "" start_day = str2datetime( self.input.s, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) end_day = str2datetime( self.input.e, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) (start_hour, start_minute) = self.input.st.split(':', 2) (end_hour, end_minute) = self.input.et.split(':', 2) start_time = create_epochsec( start_day.year, start_day.month, start_day.day, int(start_hour), int(start_minute), ) end_time = create_epochsec( end_day.year, end_day.month, end_day.day, int(end_hour), int(end_minute), ) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest( _('Getting reports failed. Start time > end time.')) param_value["start_datetime"] = "%s %s" % ( start_day.strftime("%Y/%m/%d"), self.input.st) param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et) lines = read_all_log(app, int(self.input.m), param_value["start_datetime"], param_value["end_datetime"], param_value["k"]) self.view.log_json = json_dumps(lines) return True
def _GET(self, *param, **params): self.__template__.dir = "hostby1logby1appby1" self.__template__.file = "hostby1logby1appby1" self.__template__.media = "part" appname = param[1] filename = param[2] log_config = None if not validates_log(self): self.logger.debug("Get log failed. Did not validate.") return web.badrequest(self.view.alert) config = LogViewConfigParam(LOG_VIEW_XML_FILE) config.load_xml_config() app = config.findby1application(appname) for log in app['logs']: if log['filename'] == filename: log_config = log lines = [] param_value = {} if is_param(self.input, 'k'): param_value["k"] = self.input.k else: param_value["k"] = "" start_day = str2datetime( self.input.s, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) end_day = str2datetime( self.input.e, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) (start_hour, start_minute) = self.input.st.split(':', 2) (end_hour, end_minute) = self.input.et.split(':', 2) start_time = create_epochsec( start_day.year, start_day.month, start_day.day, int(start_hour), int(start_minute), ) end_time = create_epochsec( end_day.year, end_day.month, end_day.day, int(end_hour), int(end_minute), ) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest( _('Getting reports failed. Start time > end time.')) param_value["start_datetime"] = "%s %s" % ( start_day.strftime("%Y/%m/%d"), self.input.st) param_value["end_datetime"] = "%s %s" % (end_day.strftime("%Y/%m/%d"), self.input.et) if log_config['view_rotatelog']: try: lines = read_log_with_rotate(filename, self.input.m, log_config, param_value["start_datetime"], param_value["end_datetime"], param_value["k"]) if lines is False: return web.notfound() except Exception, e: self.logger.warning("log file open error: %s" % e)
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() target = param[1] if target is None: return web.notfound() dev = param[2] if dev is None: return web.notfound() if not validates_report(self): self.logger.debug("Get report failed. Did not validate.") return web.badrequest(self.view.alert) today = datetime.datetime.today() if is_param(self.input, 'report_start_day') and not is_empty( self.input.report_start_day): start_day = str2datetime( self.input.report_start_day, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) else: start_day = today - datetime.timedelta(1) if is_param(self.input, 'report_start_time') and not is_empty( self.input.report_start_time): (start_hour, start_minute) = self.input.report_start_time.split(':', 2) start_hour = int(start_hour) start_minute = int(start_minute) else: start_hour = today.hour start_minute = today.minute if is_param( self.input, 'report_end_day') and not is_empty(self.input.report_end_day): end_day = str2datetime( self.input.report_end_day, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) else: end_day = today if is_param(self.input, 'report_end_time') and not is_empty( self.input.report_end_time): (end_hour, end_minute) = self.input.report_end_time.split(':', 2) end_hour = int(end_hour) end_minute = int(end_minute) else: end_hour = today.hour end_minute = today.minute start_time = create_epochsec( start_day.year, start_day.month, start_day.day, start_hour, start_minute, ) end_time = create_epochsec( end_day.year, end_day.month, end_day.day, end_hour, end_minute, ) if int(start_time) > int(end_time): self.logger.error("Getting reports failed. Start time > end time.") return web.badrequest( _('Getting reports failed. Start time > end time.')) if is_param(self.input, 'type') and not is_empty(self.input.type): type = self.input.type else: type = "default" if is_param(self.input, 'host') and not is_empty(self.input.host): host = self.input.host else: host = None if is_param( self.input, 'libvirt_target') and not is_empty(self.input.libvirt_target): libvirt_target = self.input.libvirt_target else: libvirt_target = None rrd = RRD(self._, self.me.languages) if host is not None: if rrd.set_rrd_dir_host(host) is False: self.logger.debug("Get report failed. Target host not found.") return web.notfound() filepath = rrd.create_graph(target, dev, type, start_time, end_time, libvirt_target) if filepath != "": self.download.type = OUTPUT_TYPE_FILE self.download.file = filepath self.download.once = True return True