Beispiel #1
0
  def test_alert_collector_purge(self):
    definition_json = self._get_port_alert_definition()

    configuration = {'hdfs-site' :
      { 'my-key': 'value1' }
    }

    collector = AlertCollector()
    cluster_configuration = self.__get_cluster_configuration()
    self.__update_cluster_configuration(cluster_configuration, configuration)

    alert = PortAlert(definition_json, definition_json['source'])
    alert.set_helpers(collector, cluster_configuration)
    alert.set_cluster("c1", "c6401.ambari.apache.org")
    self.assertEquals(6, alert.interval())

    res = alert.collect()

    alerts = collector.alerts()
    self.assertEquals(0, len(collector.alerts()))

    self.assertTrue(alerts[0] is not None)
    self.assertEquals('CRITICAL', alerts[0]['state'])

    collector.remove_by_uuid('c1f73191-4481-4435-8dae-fd380e4c0be1')
    self.assertEquals(0,len(collector.alerts()))
Beispiel #2
0
  def test_port_alert_no_sub(self):
    definition_json = { "name": "namenode_process",
      "service": "HDFS",
      "component": "NAMENODE",
      "label": "NameNode process",
      "interval": 6,
      "scope": "host",
      "enabled": True,
      "uuid": "c1f73191-4481-4435-8dae-fd380e4c0be1",
      "source": {
        "type": "PORT",
        "uri": "http://c6401.ambari.apache.org",
        "default_port": 50070,
        "reporting": {
          "ok": {
            "text": "(Unit Tests) TCP OK - {0:.4f} response time on port {1}"
          },
          "critical": {
            "text": "(Unit Tests) Could not load process info: {0}"
          }
        }
      }
    }

    cluster_configuration = self.__get_cluster_configuration()

    alert = PortAlert(definition_json, definition_json['source'])
    alert.set_helpers(AlertCollector(), cluster_configuration)
    alert.set_cluster("c1", "c6401.ambari.apache.org")

    self.assertEquals('http://c6401.ambari.apache.org', alert.uri)

    alert.collect()
Beispiel #3
0
    def test_port_alert(self, socket_connect_mock, time_mock):
        definition_json = self._get_port_alert_definition()

        configuration = {'hdfs-site': {'my-key': 'value1'}}

        collector = AlertCollector()
        cluster_configuration = self.__get_cluster_configuration()
        self.__update_cluster_configuration(cluster_configuration,
                                            configuration)

        # called 3x with 3 calls per alert
        # - 900ms and then a time.time() for the date from base_alert
        # - 2000ms and then a time.time() for the date from base_alert
        # - socket.timeout to simulate a timeout and then a time.time() for the date from base_alert
        time_mock.side_effect = [
            0, 900, 336283000000, 0, 2000, 336283100000, socket.timeout,
            336283200000
        ]

        alert = PortAlert(definition_json, definition_json['source'])
        alert.set_helpers(collector, cluster_configuration)
        alert.set_cluster("c1", "c6401.ambari.apache.org")
        self.assertEquals(6, alert.interval())

        # 900ms is OK
        alert.collect()
        alerts = collector.alerts()
        self.assertEquals(0, len(collector.alerts()))
        self.assertEquals('OK', alerts[0]['state'])

        # 2000ms is WARNING
        alert.collect()
        alerts = collector.alerts()
        self.assertEquals(0, len(collector.alerts()))
        self.assertEquals('WARNING', alerts[0]['state'])

        # throws a socket.timeout exception, causes a CRITICAL
        alert.collect()
        alerts = collector.alerts()
        self.assertEquals(0, len(collector.alerts()))
        self.assertEquals('CRITICAL', alerts[0]['state'])
Beispiel #4
0
    def test_port_alert_complex_uri(self, socket_connect_mock):
        definition_json = self._get_port_alert_definition()

        configuration = {
            'hdfs-site': {
                'my-key':
                'c6401.ambari.apache.org:2181,c6402.ambari.apache.org:2181,c6403.ambari.apache.org:2181'
            }
        }

        collector = AlertCollector()
        cluster_configuration = self.__get_cluster_configuration()
        self.__update_cluster_configuration(cluster_configuration,
                                            configuration)

        alert = PortAlert(definition_json, definition_json['source'])
        alert.set_helpers(collector, cluster_configuration)
        alert.set_cluster("c1", "c6402.ambari.apache.org")

        # use a URI that has commas to verify that we properly parse it
        alert.set_helpers(collector, cluster_configuration)
        alert.set_cluster("c1", "c6401.ambari.apache.org")
        self.assertEquals(6, alert.interval())

        alert.collect()

        alerts = collector.alerts()
        self.assertEquals(0, len(collector.alerts()))

        self.assertEquals('OK', alerts[0]['state'])
        self.assertTrue('(Unit Tests)' in alerts[0]['text'])
        self.assertTrue('response time on port 2181' in alerts[0]['text'])
Beispiel #5
0
  def test_port_alert(self, socket_connect_mock, time_mock):
    definition_json = self._get_port_alert_definition()

    configuration = { 'hdfs-site' : { 'my-key': 'value1' } }

    collector = AlertCollector()
    cluster_configuration = self.__get_cluster_configuration()
    self.__update_cluster_configuration(cluster_configuration, configuration)

    # called 3x with 3 calls per alert
    # - 900ms and then a time.time() for the date from base_alert
    # - 2000ms and then a time.time() for the date from base_alert
    # - socket.timeout to simulate a timeout and then a time.time() for the date from base_alert
    time_mock.side_effect = [0,900,336283000000,
      0,2000,336283100000,
      socket.timeout,336283200000]

    alert = PortAlert(definition_json, definition_json['source'])
    alert.set_helpers(collector, cluster_configuration)
    alert.set_cluster("c1", "c6401.ambari.apache.org")
    self.assertEquals(6, alert.interval())

    # 900ms is OK
    alert.collect()
    alerts = collector.alerts()
    self.assertEquals(0, len(collector.alerts()))
    self.assertEquals('OK', alerts[0]['state'])

    # 2000ms is WARNING
    alert.collect()
    alerts = collector.alerts()
    self.assertEquals(0, len(collector.alerts()))
    self.assertEquals('WARNING', alerts[0]['state'])

    # throws a socket.timeout exception, causes a CRITICAL
    alert.collect()
    alerts = collector.alerts()
    self.assertEquals(0, len(collector.alerts()))
    self.assertEquals('CRITICAL', alerts[0]['state'])
Beispiel #6
0
  def test_port_alert_complex_uri(self, socket_connect_mock):
    definition_json = self._get_port_alert_definition()

    configuration = {'hdfs-site' :
      { 'my-key': 'c6401.ambari.apache.org:2181,c6402.ambari.apache.org:2181,c6403.ambari.apache.org:2181'}
    }

    collector = AlertCollector()
    cluster_configuration = self.__get_cluster_configuration()
    self.__update_cluster_configuration(cluster_configuration, configuration)

    alert = PortAlert(definition_json, definition_json['source'])
    alert.set_helpers(collector, cluster_configuration)
    alert.set_cluster("c1", "c6402.ambari.apache.org")

    # use a URI that has commas to verify that we properly parse it
    alert.set_helpers(collector, cluster_configuration)
    alert.set_cluster("c1", "c6401.ambari.apache.org")
    self.assertEquals(6, alert.interval())

    alert.collect()
    
    alerts = collector.alerts()
    self.assertEquals(0, len(collector.alerts()))
    
    self.assertEquals('OK', alerts[0]['state'])
    self.assertTrue('(Unit Tests)' in alerts[0]['text'])
    self.assertTrue('response time on port 2181' in alerts[0]['text'])
Beispiel #7
0
    def test_port_alert(self, socket_connect_mock, time_mock):
        # called 3x with 3 calls per alert
        # - 900ms and then a time.time() for the date from base_alert
        # - 2000ms and then a time.time() for the date from base_alert
        # - socket.timeout to simulate a timeout and then a time.time() for the date from base_alert
        time_mock.side_effect = [
            0, 900, 336283200000, 0, 2000, 336283200000, socket.timeout,
            336283200000
        ]

        json = {
            "name": "namenode_process",
            "service": "HDFS",
            "component": "NAMENODE",
            "label": "NameNode process",
            "interval": 6,
            "scope": "host",
            "enabled": True,
            "uuid": "c1f73191-4481-4435-8dae-fd380e4c0be1",
            "source": {
                "type": "PORT",
                "uri": "{{hdfs-site/my-key}}",
                "default_port": 50070,
                "reporting": {
                    "ok": {
                        "text":
                        "(Unit Tests) TCP OK - {0:.4f} response time on port {1}"
                    },
                    "warning": {
                        "text":
                        "(Unit Tests) TCP WARN - {0:.4f} response time on port {1}",
                        "value": 1.5
                    },
                    "critical": {
                        "text":
                        "(Unit Tests) Could not load process info: {0}",
                        "value": 5.0
                    }
                }
            }
        }

        collector = AlertCollector()

        pa = PortAlert(json, json['source'])
        pa.set_helpers(collector, {'hdfs-site/my-key': 'value1'})
        self.assertEquals(6, pa.interval())

        # 900ms is OK
        pa.collect()
        alerts = collector.alerts()
        self.assertEquals(0, len(collector.alerts()))
        self.assertEquals('OK', alerts[0]['state'])

        # 2000ms is WARNING
        pa.collect()
        alerts = collector.alerts()
        self.assertEquals(0, len(collector.alerts()))
        self.assertEquals('WARNING', alerts[0]['state'])

        # throws a socket.timeout exception, causes a CRITICAL
        pa.collect()
        alerts = collector.alerts()
        self.assertEquals(0, len(collector.alerts()))
        self.assertEquals('CRITICAL', alerts[0]['state'])