Пример #1
0
    def test_collect_noUrl(self, time, socket):
        alert_meta = {
            'name': 'alert1',
            'label': 'label1',
            'serviceName': 'service1',
            'componentName': 'component1',
            'uuid': '123',
            'enabled': 'true'
        }
        alert_source_meta = {'default_port': 80}
        cluster = 'c1'
        host = 'host1'
        expected_state = 'CRITICAL'
        expected_text = 'Connection failed: Socket Timeout to host1:80'
        time.side_effect = [123, 5240, 567]
        alert = PortAlert(alert_meta, alert_source_meta, self.config)
        alert.set_cluster(cluster, host)

        def collector_side_effect(clus, data):
            self.assertEquals(data['name'], alert_meta['name'])
            self.assertEquals(data['label'], alert_meta['label'])
            self.assertEquals(data['service'], alert_meta['serviceName'])
            self.assertEquals(data['component'], alert_meta['componentName'])
            self.assertEquals(data['uuid'], alert_meta['uuid'])
            self.assertEquals(data['enabled'], alert_meta['enabled'])
            self.assertEquals(data['state'], expected_state)
            self.assertEquals(data['text'], expected_text)
            self.assertEquals(data['cluster'], cluster)
            self.assertEquals(clus, cluster)

        alert.collector = MagicMock()
        alert.collector.put = Mock(side_effect=collector_side_effect)

        alert.collect()
Пример #2
0
    def test_collect_defaultPort(self, time, socket):
        alert_meta = {
            'name': 'alert1',
            'label': 'label1',
            'serviceName': 'service1',
            'componentName': 'component1',
            'uuid': '123',
            'enabled': 'true'
        }
        alert_source_meta = {'uri': 'http://192.168.0.1', 'default_port': 80}
        cluster = 'c1'
        host = 'host1'
        expected_state = 'OK'
        expected_text = 'TCP OK - 0.2010 response on port 80'
        time.side_effect = [123, 324, 567]
        alert = PortAlert(alert_meta, alert_source_meta, self.config)
        alert.set_cluster(cluster, host)

        def collector_side_effect(clus, data):
            self.assertEquals(data['name'], alert_meta['name'])
            self.assertEquals(data['label'], alert_meta['label'])
            self.assertEquals(data['service'], alert_meta['serviceName'])
            self.assertEquals(data['component'], alert_meta['componentName'])
            self.assertEquals(data['uuid'], alert_meta['uuid'])
            self.assertEquals(data['enabled'], alert_meta['enabled'])
            self.assertEquals(data['state'], expected_state)
            self.assertEquals(data['text'], expected_text)
            self.assertEquals(data['cluster'], cluster)
            self.assertEquals(clus, cluster)

        alert.collector = MagicMock()
        alert.collector.put = Mock(side_effect=collector_side_effect)

        alert.collect()
Пример #3
0
  def test_collect_exception(self, time, socket):
    alert_meta = {
      'name': 'alert1',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true'
    }
    alert_source_meta = {
      'uri': 'http://192.168.0.1:8080',
      'default_port': 80
    }
    cluster = 'c1'
    host = 'host1'
    cluster_id = '0'
    expected_state = 'CRITICAL'
    expected_text = 'Connection failed: exception message to 192.168.0.1:8080'
    time.side_effect = [123, 345, 567]
    socket.side_effect = Exception('exception message')
    alert = PortAlert(alert_meta, alert_source_meta, self.config)
    alert.set_cluster(cluster, cluster_id, host)
    alert.configuration_builder = MagicMock()

    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['clusterId'], cluster_id)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()
Пример #4
0
  def test_collect_warning(self, time, socket):
    alert_meta = {
      'name': 'alert1',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true'
    }
    alert_source_meta = {
      'uri': 'http://192.168.0.1:8080',
      'default_port': 80
    }
    cluster = 'c1'
    host = 'host1'
    cluster_id = '0'
    expected_state = 'WARNING'
    expected_text = 'TCP OK - 3.1170 response on port 8080'
    time.side_effect = [123, 3240, 567]
    alert = PortAlert(alert_meta, alert_source_meta, self.config)
    alert.set_cluster(cluster, cluster_id, host)
    alert.configuration_builder = MagicMock()
    
    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['clusterId'], cluster_id)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()
Пример #5
0
  def test_collect_zookeeper_connectionTimeout(self, time, socket):
    alert_meta = {
      'name': 'zookeeper_server_process',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true'
    }
    alert_source_meta = {
      'uri': 'http://192.168.0.1:2181',
      'default_port': 80,
      'parameters': [
        {
          'name': 'socket.command',
          'display_name': 'Socket Command',
          'value': 'ruok',
          'description': 'test',
          'type': 'STRING',
          'visibility': 'HIDDEN'
        },
        {
          'name': 'socket.command.response',
          'display_name': 'Expected Response',
          'value': 'imok',
          'description': 'test',
          'type': 'STRING',
          'visibility': 'HIDDEN'
        }
      ]
    }
    cluster = 'c1'
    host = 'host1'
    expected_state = 'CRITICAL'
    expected_text = 'Connection failed: Socket Timeout to 192.168.0.1:2181'
    time.side_effect = [123, 5240, 567]
    alert = PortAlert(alert_meta, alert_source_meta, self.config)
    alert.set_cluster(cluster, host)
    s = socket()
    s.recv.return_value = "imok"

    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['label'], alert_meta['label'])
      self.assertEquals(data['service'], alert_meta['serviceName'])
      self.assertEquals(data['component'], alert_meta['componentName'])
      self.assertEquals(data['uuid'], alert_meta['uuid'])
      self.assertEquals(data['enabled'], alert_meta['enabled'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['cluster'], cluster)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()
Пример #6
0
    def test_collect_zookeeper_connectionTimeout(self, time, socket):
        alert_meta = {
            'name': 'zookeeper_server_process',
            'label': 'label1',
            'serviceName': 'service1',
            'componentName': 'component1',
            'uuid': '123',
            'enabled': 'true'
        }
        alert_source_meta = {
            'uri':
            'http://192.168.0.1:2181',
            'default_port':
            80,
            'parameters': [{
                'name': 'socket.command',
                'display_name': 'Socket Command',
                'value': 'ruok',
                'description': 'test',
                'type': 'STRING',
                'visibility': 'HIDDEN'
            }, {
                'name': 'socket.command.response',
                'display_name': 'Expected Response',
                'value': 'imok',
                'description': 'test',
                'type': 'STRING',
                'visibility': 'HIDDEN'
            }]
        }
        cluster = 'c1'
        host = 'host1'
        expected_state = 'CRITICAL'
        expected_text = 'Connection failed: Socket Timeout to 192.168.0.1:2181'
        time.side_effect = [123, 5240, 567]
        alert = PortAlert(alert_meta, alert_source_meta, self.config)
        alert.set_cluster(cluster, host)
        s = socket()
        s.recv.return_value = "imok"

        def collector_side_effect(clus, data):
            self.assertEquals(data['name'], alert_meta['name'])
            self.assertEquals(data['label'], alert_meta['label'])
            self.assertEquals(data['service'], alert_meta['serviceName'])
            self.assertEquals(data['component'], alert_meta['componentName'])
            self.assertEquals(data['uuid'], alert_meta['uuid'])
            self.assertEquals(data['enabled'], alert_meta['enabled'])
            self.assertEquals(data['state'], expected_state)
            self.assertEquals(data['text'], expected_text)
            self.assertEquals(data['cluster'], cluster)
            self.assertEquals(clus, cluster)

        alert.collector = MagicMock()
        alert.collector.put = Mock(side_effect=collector_side_effect)

        alert.collect()
Пример #7
0
  def test_collect_zookeeper_warning(self, time, socket):
    alert_meta = {
      'name': 'zookeeper_server_process',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true',
    }
    alert_source_meta = {
      'uri': 'http://192.168.0.1:2181',
      'default_port': 2181,
      'parameters': [
        {
          'name': 'socket.command',
          'display_name': 'Socket Command',
          'value': 'ruok',
          'description': 'test',
          'type': 'STRING',
          'visibility': 'HIDDEN'
        },
        {
          'name': 'socket.command.response',
          'display_name': 'Expected Response',
          'value': 'imok',
          'description': 'test',
          'type': 'STRING',
          'visibility': 'HIDDEN'
        }
      ]
    }
    cluster = 'c1'
    host = 'host1'
    cluster_id = '0'
    expected_state = 'WARNING'
    expected_text = 'TCP OK - 3.1170 response on port 2181'
    time.side_effect = [123, 3240, 567]
    alert = PortAlert(alert_meta, alert_source_meta, self.config)
    alert.set_cluster(cluster, cluster_id, host)
    alert.configuration_builder = MagicMock()
    s = socket()
    s.recv.return_value = "imok"

    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['clusterId'], cluster_id)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()
Пример #8
0
    def test_collect_criticalTimeoutTooBig(self, time, socket):
        alert_meta = {
            'name': 'alert1',
            'label': 'label1',
            'serviceName': 'service1',
            'componentName': 'component1',
            'uuid': '123',
            'enabled': 'true'
        }
        alert_source_meta = {
            'uri': 'http://192.168.0.1:8080',
            'default_port': 80,
            'reporting': {
                'critical': {
                    'value': 33
                }
            }
        }
        cluster = 'c1'
        host = 'host1'
        expected_state = 'CRITICAL'
        expected_text = 'Connection failed: Socket Timeout to 192.168.0.1:8080'
        time.side_effect = [120, 123, 5240, 567]
        alert = PortAlert(alert_meta, alert_source_meta)
        alert.set_cluster(cluster, host)

        def collector_side_effect(clus, data):
            self.assertEquals(data['name'], alert_meta['name'])
            self.assertEquals(data['label'], alert_meta['label'])
            self.assertEquals(data['service'], alert_meta['serviceName'])
            self.assertEquals(data['component'], alert_meta['componentName'])
            self.assertEquals(data['uuid'], alert_meta['uuid'])
            self.assertEquals(data['enabled'], alert_meta['enabled'])
            self.assertEquals(data['state'], expected_state)
            self.assertEquals(data['text'], expected_text)
            self.assertEquals(data['cluster'], cluster)
            self.assertEquals(clus, cluster)

        alert.collector = MagicMock()
        alert.collector.put = Mock(side_effect=collector_side_effect)

        alert.collect()
Пример #9
0
  def test_collect_criticalTimeoutTooBig(self, time, socket):
    alert_meta = {
      'name': 'alert1',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true'
    }
    alert_source_meta = {
      'uri': 'http://192.168.0.1:8080',
      'default_port': 80,
      'reporting': {
        'critical': {
          'value': 33
        }
      }
    }
    cluster = 'c1'
    host = 'host1'
    expected_state = 'CRITICAL'
    expected_text = 'Connection failed: Socket Timeout to 192.168.0.1:8080'
    time.side_effect = [120, 123, 5240, 567]
    alert = PortAlert(alert_meta, alert_source_meta, self.config)
    alert.set_cluster(cluster, host)

    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['label'], alert_meta['label'])
      self.assertEquals(data['service'], alert_meta['serviceName'])
      self.assertEquals(data['component'], alert_meta['componentName'])
      self.assertEquals(data['uuid'], alert_meta['uuid'])
      self.assertEquals(data['enabled'], alert_meta['enabled'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['cluster'], cluster)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()
Пример #10
0
  def test_collect_warningTimeoutChanged(self, time, socket):
    alert_meta = {
      'name': 'alert1',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true'
    }
    alert_source_meta = {
      'uri': 'http://192.168.0.1:8080',
      'default_port': 80,
      'reporting': {
        'warning': {
          'value': 4
        }
      }
    }
    cluster = 'c1'
    host = 'host1'
    expected_state = 'OK'
    expected_text = 'TCP OK - 3.1170 response on port 8080'
    time.side_effect = [123, 3240, 567]
    alert = PortAlert(alert_meta, alert_source_meta, self.config)
    alert.set_cluster(cluster, host)

    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['label'], alert_meta['label'])
      self.assertEquals(data['service'], alert_meta['serviceName'])
      self.assertEquals(data['component'], alert_meta['componentName'])
      self.assertEquals(data['uuid'], alert_meta['uuid'])
      self.assertEquals(data['enabled'], alert_meta['enabled'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['cluster'], cluster)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()
Пример #11
0
  def test_collect_exception(self, time, socket):
    alert_meta = {
      'name': 'alert1',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true'
    }
    alert_source_meta = {
      'uri': 'http://192.168.0.1:8080',
      'default_port': 80
    }
    cluster = 'c1'
    host = 'host1'
    expected_state = 'CRITICAL'
    expected_text = 'Connection failed: exception message to 192.168.0.1:8080'
    time.side_effect = [123, 345, 567]
    socket.side_effect = Exception('exception message')
    alert = PortAlert(alert_meta, alert_source_meta, self.config)
    alert.set_cluster(cluster, host)

    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['label'], alert_meta['label'])
      self.assertEquals(data['service'], alert_meta['serviceName'])
      self.assertEquals(data['component'], alert_meta['componentName'])
      self.assertEquals(data['uuid'], alert_meta['uuid'])
      self.assertEquals(data['enabled'], alert_meta['enabled'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['cluster'], cluster)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()
Пример #12
0
  def test_collect_noUrl(self, time, socket):
    alert_meta = {
      'name': 'alert1',
      'label': 'label1',
      'serviceName': 'service1',
      'componentName': 'component1',
      'uuid': '123',
      'enabled': 'true'
    }
    alert_source_meta = {
      'default_port': 80
    }
    cluster = 'c1'
    host = 'host1'
    expected_state = 'CRITICAL'
    expected_text = 'Connection failed: Socket Timeout to host1:80'
    time.side_effect = [123, 5240, 567]
    alert = PortAlert(alert_meta, alert_source_meta)
    alert.set_cluster(cluster, host)

    def collector_side_effect(clus, data):
      self.assertEquals(data['name'], alert_meta['name'])
      self.assertEquals(data['label'], alert_meta['label'])
      self.assertEquals(data['service'], alert_meta['serviceName'])
      self.assertEquals(data['component'], alert_meta['componentName'])
      self.assertEquals(data['uuid'], alert_meta['uuid'])
      self.assertEquals(data['enabled'], alert_meta['enabled'])
      self.assertEquals(data['state'], expected_state)
      self.assertEquals(data['text'], expected_text)
      self.assertEquals(data['cluster'], cluster)
      self.assertEquals(clus, cluster)

    alert.collector = MagicMock()
    alert.collector.put = Mock(side_effect=collector_side_effect)

    alert.collect()