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): (check, edit) = validates_jobsearch(self) if check is False: return web.badrequest(self.view.alert) if edit is True: # user search users = findbyname_BM(self.orm, self.input.user) users_id = [] for user in users: users_id.append(user.id) machine_name = self.input.name.strip() if is_empty(machine_name): machine_name = None if is_empty(self.input.start): start = None else: start = str2datetime(self.input.start, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0]) if is_empty(self.input.end): end = None else: end = str2datetime(self.input.end, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0], True) # machine search m_m2js = m2mj_findbyall(self.orm, machine_name, start, end, users_id, True) if not m_m2js: self.logger.debug( "Search m_m2js failed. " "Did not exist m_m2js that in accord with these query. " "name %s, user_id %s, start %s, end %s" % (machine_name, users_id, start, end) ) return web.nocontent() self.view.m_m2js = m_m2js self.view.name = self.input.name self.view.user = self.input.user self.view.status = self.input.status self.view.start = self.input.start self.view.end = self.input.end jobgroup_ids = [] for m_m2j in m_m2js: jobgroup_ids.append(m_m2j[1].jobgroup_id) jobgroup_status = self.input.status if is_empty(jobgroup_status): jobgroup_status = None jobgroups = jg_findbyalltype( self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, jobgroup_status, desc=True ) if not jobgroups: self.logger.debug( "Search jobgroups failed. " "Did not exist jobgroups that in accord with these query. " "jobgroup_ids %s, jobgroup_status %s" % (jobgroup_ids, jobgroup_status) ) return web.nocontent() else: m_m2js = m2mj_findbyall(self.orm) self.view.m_m2js = m_m2js self.view.name = "" self.view.user = "" self.view.status = "" self.view.start = "" self.view.end = "" self.view.m_m2js = m_m2js jobgroup_ids = [] for m_m2j in m_m2js: jobgroup_ids.append(m_m2j[1].jobgroup_id) jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, desc=True) self.view.JOBGROUP_STATUS = JOBGROUP_STATUS self.view.HYPERVISOR = MACHINE_HYPERVISOR if self.input.has_key("p") is True: start = int(self.input.p) else: start = 0 self.view.date_format = DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][1] self.view.pager = Pager(jobgroups, start, JOB_LIST_RANGE) return True
def _GET(self, *param, **params): (host_id, guest_id) = self.chk_guestby1(param) if guest_id is None: return web.notfound() model = findbyguest1(self.orm, guest_id) # virt self.kvc = KaresansuiVirtConnection() try: domname = self.kvc.uuid_to_domname(model.uniq_key) if not domname: return web.notfound() finally: self.kvc.close() (check, edit) = validates_jobsearch(self) if check is False: return web.badrequest(self.view.alert) if edit is True: # user search users = findbyname_BM(self.orm, self.input.user) users_id = [] for user in users: users_id.append(user.id) if is_empty(self.input.start): start = None else: start = str2datetime(self.input.start, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) if is_empty(self.input.end): end = None else: end = str2datetime(self.input.end, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0],True) # machine search m_m2js = m2mj_findbyguest(self.orm, guest_id, start, end, users_id, ) if not m_m2js: self.logger.debug("Search m_m2js failed. " "Did not exist m_m2js that in accord with these query. " "guest_id %s, start %s, end %s, users_id %s" % (guest_id, start, end, users_id)) return web.nocontent() self.view.m_m2js = m_m2js self.view.user = self.input.user self.view.status = self.input.status self.view.start = self.input.start self.view.end = self.input.end jobgroup_ids = [] for m_m2j in m_m2js: jobgroup_ids.append(m_m2j[1].jobgroup_id) jobgroup_status = self.input.status if is_empty(jobgroup_status): jobgroup_status = None jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, jobgroup_status, desc=True) if not jobgroups: self.logger.debug("Search jobgroups failed. " "Did not exist jobgroups that in accord with these query." "jobgroup_ids %s, jobgroup_status %s" % (jobgroup_ids, jobgroup_status)) return web.nocontent() else: m_m2js = m2mj_findbyguest(self.orm, guest_id) self.view.m_m2js = m_m2js self.view.user = '' self.view.status = '' self.view.start = '' self.view.end = '' jobgroup_ids = [] for m_m2j in m_m2js: jobgroup_ids.append(m_m2j[1].jobgroup_id) jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, desc=True) self.view.JOBGROUP_STATUS = JOBGROUP_STATUS self.view.HYPERVISOR = MACHINE_HYPERVISOR if self.input.has_key('p') is True: if validates_page(self) is True: start = int(self.input.p) else: return web.badrequest(self.view.alert) else: start = 0 self.view.date_format = DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][1] self.view.pager = Pager(jobgroups, start, JOB_LIST_RANGE) return True
def _GET(self, *param, **params): host_id = self.chk_hostby1(param) if host_id is None: return web.notfound() (check, edit) = validates_jobsearch(self) if check is False: return web.badrequest(self.view.alert) if edit is True: users = findbyname_BM(self.orm, self.input.user) users_id = [] for user in users: users_id.append(user.id) machine_name = self.input.name.strip() if is_empty(machine_name): machine_name = None if is_empty(self.input.start): start = None else: start = str2datetime( self.input.start, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0]) if is_empty(self.input.end): end = None else: end = str2datetime( self.input.end, DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0], True) m_m2js = m2mj_findbyall(self.orm, machine_name, start, end, users_id, True) if not m_m2js: self.logger.debug( "Search m_m2js failed. " "Did not exist m_m2js that in accord with these query. " "name %s, user_id %s, start %s, end %s" % (machine_name, users_id, start, end)) return web.nocontent() self.view.m_m2js = m_m2js self.view.name = self.input.name self.view.user = self.input.user self.view.status = self.input.status self.view.start = self.input.start self.view.end = self.input.end jobgroup_ids = [] for m_m2j in m_m2js: jobgroup_ids.append(m_m2j[1].jobgroup_id) jobgroup_status = self.input.status if is_empty(jobgroup_status): jobgroup_status = None jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, jobgroup_status, desc=True) if not jobgroups: self.logger.debug( "Search jobgroups failed. " "Did not exist jobgroups that in accord with these query. " "jobgroup_ids %s, jobgroup_status %s" % (jobgroup_ids, jobgroup_status)) return web.nocontent() else: m_m2js = m2mj_findbyhost(self.orm, host_id) self.view.m_m2js = m_m2js self.view.name = '' self.view.user = '' self.view.status = '' self.view.start = '' self.view.end = '' jobgroup_ids = [] for m_m2j in m_m2js: jobgroup_ids.append(m_m2j[1].jobgroup_id) jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, desc=True) self.view.JOBGROUP_STATUS = JOBGROUP_STATUS self.view.HYPERVISOR = MACHINE_HYPERVISOR if self.input.has_key('p') is True: if validates_page(self) is True: start = int(self.input.p) else: return web.badrequest(self.view.alert) else: start = 0 self.view.date_format = DEFAULT_LANGS[ self.me.languages]['DATE_FORMAT'][1] self.view.pager = Pager(jobgroups, start, JOB_LIST_RANGE) 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