Exemple #1
0
    def basc_field_result(self, log, field_name):
        """
        Return (0, result) to print for a field
        """
        # pylint: disable=too-many-branches
        agent = self.basc_agent
        hostname = agent.bea_host.sh_hostname
        ret = 0
        if field_name == barrele_constant.BARRELE_FIELD_HOST:
            result = hostname
        elif field_name == barrele_constant.BARRELE_FIELD_UP:
            if self._basc_is_up is None:
                log.cl_error("up status of host [%s] is not inited", hostname)
                ret = -1
                result = clog.ERROR_MSG
            elif self._basc_is_up:
                result = clog.colorful_message(
                    clog.COLOR_GREEN, barrele_constant.BARRELE_AGENT_UP)
            else:
                result = clog.colorful_message(
                    clog.COLOR_RED, barrele_constant.BARRELE_AGENT_DOWN)
        elif field_name == barrele_constant.BARRELE_FIELD_COLLECTD:
            if self.basc_running_collectd is None:
                log.cl_error("Collectd status of host [%s] is not inited",
                             hostname)
                result = clog.ERROR_MSG
                ret = -1
            elif self.basc_running_collectd < 0:
                result = clog.ERROR_MSG
            elif self.basc_running_collectd:
                result = clog.colorful_message(
                    clog.COLOR_GREEN, barrele_constant.BARRELE_AGENT_ACTIVE)
            else:
                result = clog.colorful_message(
                    clog.COLOR_RED, barrele_constant.BARRELE_AGENT_INACTIVE)
        elif field_name == barrele_constant.BARRELE_FIELD_COLLECTD_VERSION:
            if self.basc_collectd_version is None:
                log.cl_error("Collectd version of host [%s] is not inited",
                             hostname)
                result = clog.ERROR_MSG
                ret = -1
            else:
                result = self.basc_collectd_version
        else:
            log.cl_error("unknown field [%s] of agent", field_name)
            result = clog.ERROR_MSG
            ret = -1

        if self.basc_failed:
            ret = -1
        return ret, result
Exemple #2
0
def print_field(log, field_name, value):
    """
    print one field
    """
    field = clog.colorful_message(clog.COLOR_TABLE_FIELDNAME,
                                  "%s: " % field_name)
    log.cl_stdout("%s%s", field, value)
Exemple #3
0
def table_add_field_names(table, field_names):
    """
    Add field names of a table
    """
    colorful_field_names = []
    for field_name in field_names:
        colorful_field_names.append(
            clog.colorful_message(clog.COLOR_TABLE_FIELDNAME, field_name))
    table.field_names = colorful_field_names
Exemple #4
0
    def bssc_field_result(self, log, field_name):
        """
        Return (0, result) to print for a field
        """
        # pylint: disable=too-many-branches,too-many-statements
        server = self.bssc_server
        hostname = server.bes_server_host.sh_hostname
        ret = 0
        if field_name == barrele_constant.BARRELE_FIELD_HOST:
            result = hostname
        elif field_name == barrele_constant.BARRELE_FIELD_UP:
            if self._bssc_is_up is None:
                log.cl_error("up status of host [%s] is not inited", hostname)
                ret = -1
                result = clog.ERROR_MSG
            elif self._bssc_is_up:
                result = clog.colorful_message(
                    clog.COLOR_GREEN, barrele_constant.BARRELE_AGENT_UP)
            else:
                result = clog.colorful_message(
                    clog.COLOR_RED, barrele_constant.BARRELE_AGENT_DOWN)
        elif field_name == barrele_constant.BARRELE_FIELD_GRAFANA:
            if self.bssc_running_grafana is None:
                log.cl_error("Grafana status of host [%s] is not inited",
                             hostname)
                result = clog.ERROR_MSG
                ret = -1
            elif self.bssc_running_grafana < 0:
                result = clog.ERROR_MSG
            elif self.bssc_running_grafana:
                result = clog.colorful_message(
                    clog.COLOR_GREEN, barrele_constant.BARRELE_AGENT_RUNNING)
            else:
                result = clog.colorful_message(
                    clog.COLOR_RED, barrele_constant.BARRELE_AGENT_STOPPED)
        elif field_name == barrele_constant.BARRELE_FIELD_INFLUXDB:
            if self.bssc_running_influxdb is None:
                log.cl_error("Influxdb status of host [%s] is not inited",
                             hostname)
                result = clog.ERROR_MSG
                ret = -1
            elif self.bssc_running_influxdb < 0:
                result = clog.ERROR_MSG
            elif self.bssc_running_influxdb:
                result = clog.colorful_message(
                    clog.COLOR_GREEN, barrele_constant.BARRELE_AGENT_ACTIVE)
            else:
                result = clog.colorful_message(
                    clog.COLOR_RED, barrele_constant.BARRELE_AGENT_INACTIVE)

        elif field_name == barrele_constant.BARRELE_FIELD_INFLUXDB_VERSION:
            if self.bssc_influxdb_version is None:
                log.cl_error("Influxdb version of host [%s] is not inited",
                             hostname)
                result = clog.ERROR_MSG
                ret = -1
            else:
                result = self.bssc_influxdb_version
        elif field_name == barrele_constant.BARRELE_FIELD_GRAFANA_VERSION:
            if self.bssc_grafana_version is None:
                log.cl_error("Grafana version of host [%s] is not inited",
                             hostname)
                result = clog.ERROR_MSG
                ret = -1
            else:
                result = self.bssc_grafana_version
        else:
            log.cl_error("unknown field [%s] of server", field_name)
            result = clog.ERROR_MSG
            ret = -1

        if self.bssc_failed:
            ret = -1
        return ret, result
Exemple #5
0
def table_set_sortby(table, field_name):
    """
    Set the field to sortby
    """
    table.sortby = clog.colorful_message(clog.COLOR_TABLE_FIELDNAME,
                                         field_name)