Exemple #1
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        watch_id = param[1]
        if watch_id is None: return web.notfound()

        watch = w_findby1(self.orm, watch_id)
        self.view.watch = watch
        self.view.plugins = WATCH_PLUGINS

        plugin_selector = plugin_selector_to_dict(watch.plugin_selector)
        self.view.plugin_selector = plugin_selector

        if watch.plugin == COLLECTD_PLUGIN_LIBVIRT:
            libvirt_type = ""
            if plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['VCPU']:
                libvirt_type = "vcpu"
            elif plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['CPU_TOTAL']:
                libvirt_type = "cpu_total"
            elif plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['DISK_OPS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['DISK_OCTETS']:
                libvirt_type = "disk"
            elif plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_OCTETS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_PACKETS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_ERRORS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_DROPPED']:
                libvirt_type = "interface"

            self.view.libvirt_type = libvirt_type

        if self.is_mode_input() is True:
            warning_value = threshold_value_to_dict(watch.warning_value)
            failure_value = threshold_value_to_dict(watch.failure_value)
            self.view.threshold_value_1 = warning_value.values()[0]
            self.view.threshold_value_2 = failure_value.values()[0]
            self.view.threshold_type = failure_value.keys()[0]
            self.view.use_percentage = watch.is_failure_percentage

            self.view.supported_langs = DEFAULT_LANGS.keys()

        self.view.memory_size = string.atol(
            get_proc_meminfo()["MemTotal"][0]) / 1024
        ## disk info
        self.view.disk_size_info = {}
        for disk_data in get_fs_info():
            disk_target = re.sub(r'^/dev/', '', disk_data['Filesystem'])
            disk_target = re.sub(r'/', '_', disk_target)
            self.view.disk_size_info[disk_target] = disk_data['1048576-blocks']
        self.view.interface_type = COLLECTD_INTERFACE_TYPE
        self.view.processer_num = len(get_proc_cpuinfo().keys())
        self.view.mta = "%s:%s" % (
            karesansui.config['application.mail.server'],
            karesansui.config['application.mail.port'])
        self.view.watch_interval = WATCH_INTERVAL

        return True
Exemple #2
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        watch_id = param[1]
        if watch_id is None: return web.notfound()

        watch = w_findby1(self.orm, watch_id)
        self.view.watch = watch
        self.view.plugins = WATCH_PLUGINS

        plugin_selector = plugin_selector_to_dict(watch.plugin_selector)
        self.view.plugin_selector = plugin_selector

        if watch.plugin == COLLECTD_PLUGIN_LIBVIRT:
            libvirt_type = ""
            if plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['VCPU']:
                libvirt_type = "vcpu"
            elif plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['CPU_TOTAL']:
                libvirt_type = "cpu_total"
            elif plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['DISK_OPS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['DISK_OCTETS']:
                libvirt_type = "disk"
            elif plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_OCTETS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_PACKETS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_ERRORS'] or \
                    plugin_selector['type'] == COLLECTD_LIBVIRT_TYPE['IF_DROPPED']:
                libvirt_type = "interface"

            self.view.libvirt_type = libvirt_type

        if self.is_mode_input() is True:
            warning_value = threshold_value_to_dict(watch.warning_value)
            failure_value = threshold_value_to_dict(watch.failure_value)
            self.view.threshold_value_1 = warning_value.values()[0]
            self.view.threshold_value_2 = failure_value.values()[0]
            self.view.threshold_type = failure_value.keys()[0]
            self.view.use_percentage = watch.is_failure_percentage

            self.view.supported_langs = DEFAULT_LANGS.keys()

        self.view.memory_size = string.atol(get_proc_meminfo()["MemTotal"][0]) / 1024
        ## disk info 
        self.view.disk_size_info = {}
        for disk_data in get_fs_info():
            disk_target = re.sub(r'^/dev/', '', disk_data['Filesystem'])
            disk_target = re.sub(r'/', '_', disk_target)
            self.view.disk_size_info[disk_target] = disk_data['1048576-blocks']
        self.view.interface_type = COLLECTD_INTERFACE_TYPE
        self.view.processer_num = len(get_proc_cpuinfo().keys())
        self.view.mta = "%s:%s" % (karesansui.config['application.mail.server'],
                                   karesansui.config['application.mail.port'])
        self.view.watch_interval = WATCH_INTERVAL

        return True
Exemple #3
0
    def _GET(self, *param, **params):

        self.view.database_bind = karesansui.config['database.bind'] 
        self.view.default_locale = karesansui.config['application.default.locale'] 
        self.view.locales = DEFAULT_LANGS.keys()

        if karesansui_database_exists() is True:
            return web.tempredirect("/", absolute=False)

        if self.is_mode_input():
            return True
        else:
            return True
 
        return True
Exemple #4
0
    def _GET(self, *param, **params):
        user_id = param[0]
        if not validates_param_id(self, user_id):
            self.logger.debug("Failed to update account. the value of parameter is invalid.")
            return web.notfound(self.view.alert)

        user = findby1(self.orm, user_id)
        if not user:
            self.logger.debug("Failed to get account - id=%s" % user_id)
            return web.notfound()
        self.view.user = user

        if self.is_mode_input():
            locales = DEFAULT_LANGS.keys()
            self.view.locales = locales
        return True
Exemple #5
0
    def _GET(self, *param, **params):
        user_id = param[0]
        if not validates_param_id(self, user_id):
            self.logger.debug(
                "Failed to update account. the value of parameter is invalid.")
            return web.notfound(self.view.alert)

        user = findby1(self.orm, user_id)
        if not user:
            self.logger.debug("Failed to get account - id=%s" % user_id)
            return web.notfound()
        self.view.user = user

        if self.is_mode_input():
            locales = DEFAULT_LANGS.keys()
            self.view.locales = locales
        return True
Exemple #6
0
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug("Failed to get account. the value of query is invalid. - query=%s" % self.input.q)
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Failed to get account. the value of page is invalid. - page=%s" % self.input.p)
            return web.badrequest(self.view.alert)

        if is_param(self.input, "q"):
            users = findbyand(self.orm, self.input.q)
            if not users:
                self.logger.debug("Failed to get account. No such account. - query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            users = findbyall(self.orm)
            self.view.search_value = ""
            if not users:
                self.logger.debug("Failed to get account. No accounts found.")
                return web.notfound()

        if is_param(self.input, "p"):
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(users, start, USER_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug("Failed to get account. Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            locales = DEFAULT_LANGS.keys()
            self.view.locales = locales
            self.view.user = new('', '', '', '', '')

        self.view.input = self.input
        return True
Exemple #7
0
    def _GET(self, *param, **params):
        if not validates_query(self):
            self.logger.debug("Failed to get account. the value of query is invalid. - query=%s" % self.input.q)
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Failed to get account. the value of page is invalid. - page=%s" % self.input.p)
            return web.badrequest(self.view.alert)

        if is_param(self.input, "q"):
            users = findbyand(self.orm, self.input.q)
            if not users:
                self.logger.debug("Failed to get account. No such account. - query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            users = findbyall(self.orm)
            self.view.search_value = ""
            if not users:
                self.logger.debug("Failed to get account. No accounts found.")
                return web.notfound()

        if is_param(self.input, "p"):
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(users, start, USER_LIST_RANGE)
        if not pager.exist_now_page():
            self.logger.debug("Failed to get account. Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager

        if self.is_mode_input():
            locales = DEFAULT_LANGS.keys()
            self.view.locales = locales
            self.view.user = new('', '', '', '', '')

        self.view.input = self.input
        return True
Exemple #8
0
 def _GET(self, *param, **params):
     if self.is_mode_input():
         self.view.locales = DEFAULT_LANGS.keys()
     return True
Exemple #9
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if self.is_mode_input() is True:
            self.view.plugins = WATCH_PLUGINS
            self.view.cpu_type_instance = COLLECTD_CPU_TYPE_INSTANCE
            self.view.memory_type_instance = COLLECTD_MEMORY_TYPE_INSTANCE
            self.view.df_ds = COLLECTD_DF_DS
            self.view.interface_type = COLLECTD_INTERFACE_TYPE
            self.view.interface_ds = COLLECTD_INTERFACE_DS
            self.view.load_ds = COLLECTD_LOAD_DS

            cpu_logical_number = len(get_proc_cpuinfo())
            self.view.cpu_logical_number = range(1, cpu_logical_number+1)
            self.view.memory_size = string.atol(get_proc_meminfo()["MemTotal"][0]) / 1024
            self.view.df_list = get_fs_info()
            self.view.interface_list = get_ifconfig_info().keys()

            ## guest os list
            from karesansui.lib.utils import get_dom_list
            from karesansui.lib.virt.virt import KaresansuiVirtConnection
            from karesansui.lib.merge import MergeGuest
            self.view.dom_list = get_dom_list()

            dom_info = {}
            for domname in get_dom_list():
                kvc = KaresansuiVirtConnection()
                virt = kvc.search_kvg_guests(domname)[0]
                dom_info[domname] = {}
                dom_info[domname]['network'] = []
                dom_info[domname]['disk'] = []
                dom_info[domname]['disk_size'] = {}
                for net_dev in virt.get_interface_info():
                    dom_info[domname]['network'].append(net_dev['target']['dev'])
                for disk in virt.get_disk_info():
                    dom_info[domname]['disk'].append(disk['target']['dev'])
                    dom_info[domname]['disk_size'][disk['target']['dev']] = disk['source']['size']

                dom_info[domname]['vcpu'] = virt.get_vcpus_info()['max_vcpus']
                kvc.close()
            self.view.dom_info = dom_info

            ## disk info 
            self.view.disk_size_info = {}
            for disk_data in get_fs_info():
                self.view.disk_size_info[disk_data['Filesystem']] = disk_data['1048576-blocks']

            self.view.processer_num = len(get_proc_cpuinfo().keys())
            self.view.supported_langs = DEFAULT_LANGS.keys()
            self.view.myaddress = self.me.email
            self.view.mta = "%s:%s" % (karesansui.config['application.mail.server'],
                                       karesansui.config['application.mail.port'])
            self.view.alert_trigger_count = DEFAULT_ALERT_TRIGGER_COUNT;
            self.view.slient_period = DEFAULT_SLIENT_PERIOD;
            return True

        if not validates_query(self):
            self.logger.debug("Show watch is failed, "
                              "Invalid query value "
                              "- query=%s" % self.input.q)
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Show watch is failed, "
                              "Invalid page value - page=%s" % self.input.p)
            return web.badrequest(self.view.alert)

        if is_param(self.input, 'q') is True:
            watchs = w_findbyname_or_plugin(self.orm, self.input.q)
            if not watchs:
                self.logger.debug("Show watch is failed, "
                                  "Could not find watch "
                                  "- query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            watchs = w_findbyall(self.orm)
            self.view.search_value = ""

        if is_param(self.input, 'p') is True:
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(watchs, start, WATCH_LIST_RANGE)
        if not pager.exist_now_page() and is_param(self.input, 'p') is True:
            self.logger.debug("Show watch is failed, "
                              "Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager
        self.view.input = self.input

        return True
Exemple #10
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if self.is_mode_input() is True:
            self.view.plugins = WATCH_PLUGINS
            self.view.cpu_type_instance = COLLECTD_CPU_TYPE_INSTANCE
            self.view.memory_type_instance = COLLECTD_MEMORY_TYPE_INSTANCE
            self.view.df_ds = COLLECTD_DF_DS
            self.view.interface_type = COLLECTD_INTERFACE_TYPE
            self.view.interface_ds = COLLECTD_INTERFACE_DS
            self.view.load_ds = COLLECTD_LOAD_DS

            cpu_logical_number = len(get_proc_cpuinfo())
            self.view.cpu_logical_number = range(1, cpu_logical_number + 1)
            self.view.memory_size = string.atol(
                get_proc_meminfo()["MemTotal"][0]) / 1024
            self.view.df_list = get_fs_info()
            self.view.interface_list = get_ifconfig_info().keys()

            ## guest os list
            from karesansui.lib.utils import get_dom_list
            from karesansui.lib.virt.virt import KaresansuiVirtConnection
            from karesansui.lib.merge import MergeGuest
            self.view.dom_list = get_dom_list()

            dom_info = {}
            for domname in get_dom_list():
                kvc = KaresansuiVirtConnection()
                virt = kvc.search_kvg_guests(domname)[0]
                dom_info[domname] = {}
                dom_info[domname]['network'] = []
                dom_info[domname]['disk'] = []
                dom_info[domname]['disk_size'] = {}
                for net_dev in virt.get_interface_info():
                    dom_info[domname]['network'].append(
                        net_dev['target']['dev'])
                for disk in virt.get_disk_info():
                    dom_info[domname]['disk'].append(disk['target']['dev'])
                    dom_info[domname]['disk_size'][
                        disk['target']['dev']] = disk['source']['size']

                dom_info[domname]['vcpu'] = virt.get_vcpus_info()['max_vcpus']
                kvc.close()
            self.view.dom_info = dom_info

            ## disk info
            self.view.disk_size_info = {}
            for disk_data in get_fs_info():
                self.view.disk_size_info[
                    disk_data['Filesystem']] = disk_data['1048576-blocks']

            self.view.processer_num = len(get_proc_cpuinfo().keys())
            self.view.supported_langs = DEFAULT_LANGS.keys()
            self.view.myaddress = self.me.email
            self.view.mta = "%s:%s" % (
                karesansui.config['application.mail.server'],
                karesansui.config['application.mail.port'])
            self.view.alert_trigger_count = DEFAULT_ALERT_TRIGGER_COUNT
            self.view.slient_period = DEFAULT_SLIENT_PERIOD
            return True

        if not validates_query(self):
            self.logger.debug("Show watch is failed, "
                              "Invalid query value "
                              "- query=%s" % self.input.q)
            return web.badrequest(self.view.alert)

        if not validates_page(self):
            self.logger.debug("Show watch is failed, "
                              "Invalid page value - page=%s" % self.input.p)
            return web.badrequest(self.view.alert)

        if is_param(self.input, 'q') is True:
            watchs = w_findbyname_or_plugin(self.orm, self.input.q)
            if not watchs:
                self.logger.debug("Show watch is failed, "
                                  "Could not find watch "
                                  "- query=%s" % self.input.q)
                return web.nocontent()
            self.view.search_value = self.input.q
        else:
            watchs = w_findbyall(self.orm)
            self.view.search_value = ""

        if is_param(self.input, 'p') is True:
            start = int(self.input.p)
        else:
            start = 0

        pager = Pager(watchs, start, WATCH_LIST_RANGE)
        if not pager.exist_now_page() and is_param(self.input, 'p') is True:
            self.logger.debug("Show watch is failed, "
                              "Could not find page - page=%s" % self.input.p)
            return web.nocontent()

        self.view.pager = pager
        self.view.input = self.input

        return True