Ejemplo n.º 1
0
def execute(parameters=None, host_name=None):
  """
  Returns a tuple containing the result code and a pre-formatted result label

  Keyword arguments:
  parameters (dictionary): a mapping of parameter key to value
  host_name (string): the name of this host where the alert is running
  """

  if parameters is None:
    return (RESULT_CODE_UNKNOWN, ['There were no parameters supplied to the script.'])

  flume_conf_directory = None
  if FLUME_CONF_DIR_KEY in parameters:
    flume_conf_directory = parameters[FLUME_CONF_DIR_KEY]

  if flume_conf_directory is None:
    return (RESULT_CODE_UNKNOWN, ['The Flume configuration directory is a required parameter.'])

  if host_name is None:
    host_name = socket.getfqdn()

  processes = get_flume_status(flume_conf_directory, FLUME_RUN_DIR)
  expected_agents = find_expected_agent_names(flume_conf_directory)

  alert_label = ''
  alert_state = RESULT_CODE_OK

  if len(processes) == 0 and len(expected_agents) == 0:
    alert_label = 'No agents defined on {0}'.format(host_name)
  else:
    ok = []
    critical = []
    text_arr = []

    for process in processes:
      if not process.has_key('status') or process['status'] == 'NOT_RUNNING':
        critical.append(process['name'])
      else:
        ok.append(process['name'])

    if len(critical) > 0:
      text_arr.append("{0} {1} NOT running".format(", ".join(critical),
        "is" if len(critical) == 1 else "are"))

    if len(ok) > 0:
      text_arr.append("{0} {1} running".format(", ".join(ok),
        "is" if len(ok) == 1 else "are"))

    plural = len(critical) > 1 or len(ok) > 1
    alert_label = "Agent{0} {1} {2}".format(
      "s" if plural else "",
      " and ".join(text_arr),
      "on " + host_name)

    alert_state = RESULT_CODE_CRITICAL if len(critical) > 0 else RESULT_CODE_OK

  return (alert_state, [alert_label])
Ejemplo n.º 2
0
    def status(self, env):
        import params
        env.set_params(params)
        processes = get_flume_status(params.flume_conf_dir, params.flume_run_dir)
        expected_agents = find_expected_agent_names(params.flume_conf_dir)

        json = {}
        json['processes'] = processes
        self.put_structured_out(json)

        if len(expected_agents) > 0:
            for proc in processes:
                if not proc.has_key('status') or proc['status'] == 'NOT_RUNNING':
                    raise ComponentIsNotRunning()
        elif len(expected_agents) == 0 and 'INSTALLED' == get_desired_state():
            raise ComponentIsNotRunning()
Ejemplo n.º 3
0
  def status(self, env):
    import params
    env.set_params(params)
    processes = get_flume_status(params.flume_conf_dir, params.flume_run_dir)
    expected_agents = find_expected_agent_names(params.flume_conf_dir)

    json = {}
    json['processes'] = processes
    self.put_structured_out(json)

    # only throw an exception if there are agents defined and there is a
    # problem with the processes; if there are no agents defined, then
    # the service should report STARTED (green) ONLY if the desired state is started.  otherwise, INSTALLED (red)
    if len(expected_agents) > 0:
      for proc in processes:
        if not proc.has_key('status') or proc['status'] == 'NOT_RUNNING':
          raise ComponentIsNotRunning()
    elif len(expected_agents) == 0 and 'INSTALLED' == get_desired_state():
      raise ComponentIsNotRunning()
Ejemplo n.º 4
0
  def status(self, env):
    import params
    env.set_params(params)
    processes = get_flume_status(params.flume_conf_dir, params.flume_run_dir)
    expected_agents = find_expected_agent_names(params.flume_conf_dir)

    json = {}
    json['processes'] = processes
    self.put_structured_out(json)

    # only throw an exception if there are agents defined and there is a 
    # problem with the processes; if there are no agents defined, then 
    # the service should report STARTED (green) ONLY if the desired state is started.  otherwise, INSTALLED (red)
    if len(expected_agents) > 0:
      for proc in processes:
        if not proc.has_key('status') or proc['status'] == 'NOT_RUNNING':
          raise ComponentIsNotRunning()
    elif len(expected_agents) == 0 and 'INSTALLED' == get_desired_state():
      raise ComponentIsNotRunning()
Ejemplo n.º 5
0
    def status(self, env):
        import params
        env.set_params(params)
        processes = get_flume_status(params.flume_conf_dir,
                                     params.flume_run_dir)
        expected_agents = find_expected_agent_names(params.flume_conf_dir)

        json = {}
        json['processes'] = processes
        json['alerts'] = []

        alert = {}
        alert['name'] = 'flume_agent'
        alert['label'] = 'Flume Agent process'

        if len(processes) == 0 and len(expected_agents) == 0:
            alert['state'] = 'OK'

            if not params.hostname is None:
                alert['text'] = 'No agents defined on ' + params.hostname
            else:
                alert['text'] = 'No agents defined'

        else:
            crit = []
            ok = []

            for proc in processes:
                if not proc.has_key(
                        'status') or proc['status'] == 'NOT_RUNNING':
                    crit.append(proc['name'])
                else:
                    ok.append(proc['name'])

            text_arr = []

            if len(crit) > 0:
                text_arr.append("{0} {1} NOT running".format(
                    ", ".join(crit), "is" if len(crit) == 1 else "are"))

            if len(ok) > 0:
                text_arr.append("{0} {1} running".format(
                    ", ".join(ok), "is" if len(ok) == 1 else "are"))

            plural = len(crit) > 1 or len(ok) > 1
            alert['text'] = "Agent{0} {1} {2}".format(
                "s" if plural else "", " and ".join(text_arr),
                "" if params.hostname is None else "on " +
                str(params.hostname))

            alert['state'] = 'CRITICAL' if len(crit) > 0 else 'OK'

        json['alerts'].append(alert)
        self.put_structured_out(json)

        # only throw an exception if there are agents defined and there is a
        # problem with the processes; if there are no agents defined, then
        # the service should report STARTED (green) ONLY if the desired state is started.  otherwise, INSTALLED (red)
        if len(expected_agents) > 0:
            for proc in processes:
                if not proc.has_key(
                        'status') or proc['status'] == 'NOT_RUNNING':
                    raise ComponentIsNotRunning()
        elif len(expected_agents) == 0 and 'INSTALLED' == get_desired_state():
            raise ComponentIsNotRunning()