Пример #1
0
  def test_script_alert(self):
    definition_json = self._get_script_alert_definition()

    # normally set by AlertSchedulerHandler
    definition_json['source']['stacks_directory'] = os.path.join('ambari_agent', 'dummy_files')
    definition_json['source']['common_services_directory'] = os.path.join('ambari_agent', 'common-services')
    definition_json['source']['host_scripts_directory'] = os.path.join('ambari_agent', 'host_scripts')

    configuration = {'foo-site' :
      { 'bar': 'rendered-bar', 'baz' : 'rendered-baz' }
    }

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

    alert = ScriptAlert(definition_json, definition_json['source'], MagicMock())
    alert.set_helpers(collector, cluster_configuration )
    alert.set_cluster("c1", "c6401.ambari.apache.org")
    
    self.assertEquals(definition_json['source']['path'], alert.path)
    self.assertEquals(definition_json['source']['stacks_directory'], alert.stacks_dir)
    self.assertEquals(definition_json['source']['common_services_directory'], alert.common_services_dir)
    self.assertEquals(definition_json['source']['host_scripts_directory'], alert.host_scripts_dir)

    alert.collect()

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

    self.assertEquals('WARNING', alerts[0]['state'])
    self.assertEquals('bar is rendered-bar, baz is rendered-baz', alerts[0]['text'])
Пример #2
0
    def test_configuration_updates(self):
        definition_json = self._get_script_alert_definition()

        # normally set by AlertSchedulerHandler
        definition_json['source']['stacks_directory'] = os.path.join(
            'ambari_agent', 'dummy_files')
        definition_json['source']['common_services_directory'] = os.path.join(
            'ambari_agent', 'common-services')
        definition_json['source']['host_scripts_directory'] = os.path.join(
            'ambari_agent', 'host_scripts')

        configuration = {
            'foo-site': {
                'bar': 'rendered-bar',
                'baz': 'rendered-baz'
            }
        }

        # populate the configuration cache with the initial configs
        collector = AlertCollector()
        cluster_configuration = self.__get_cluster_configuration()
        self.__update_cluster_configuration(cluster_configuration,
                                            configuration)

        # run the alert and verify the output
        alert = ScriptAlert(definition_json, definition_json['source'],
                            MagicMock())
        alert.set_helpers(collector, cluster_configuration)
        alert.set_cluster("c1", "c6401.ambari.apache.org")
        alert.collect()

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

        self.assertEquals('WARNING', alerts[0]['state'])
        self.assertEquals('bar is rendered-bar, baz is rendered-baz',
                          alerts[0]['text'])

        # now update only the configs and run the same alert again and check
        # for different output
        configuration = {
            'foo-site': {
                'bar': 'rendered-bar2',
                'baz': 'rendered-baz2'
            }
        }

        # populate the configuration cache with the initial configs
        self.__update_cluster_configuration(cluster_configuration,
                                            configuration)

        alert.collect()

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

        self.assertEquals('WARNING', alerts[0]['state'])
        self.assertEquals('bar is rendered-bar2, baz is rendered-baz2',
                          alerts[0]['text'])
Пример #3
0
  def test_configuration_updates(self):
    definition_json = self._get_script_alert_definition()

    # normally set by AlertSchedulerHandler
    definition_json['source']['stacks_directory'] = os.path.join('ambari_agent', 'dummy_files')
    definition_json['source']['common_services_directory'] = os.path.join('ambari_agent', 'common-services')
    definition_json['source']['host_scripts_directory'] = os.path.join('ambari_agent', 'host_scripts')

    configuration = {'foo-site' :
      { 'bar': 'rendered-bar', 'baz' : 'rendered-baz' }
    }

    # populate the configuration cache with the initial configs
    collector = AlertCollector()
    cluster_configuration = self.__get_cluster_configuration()
    self.__update_cluster_configuration(cluster_configuration, configuration)

    # run the alert and verify the output
    alert = ScriptAlert(definition_json, definition_json['source'], MagicMock())
    alert.set_helpers(collector, cluster_configuration )
    alert.set_cluster("c1", "c6401.ambari.apache.org")
    alert.collect()

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

    self.assertEquals('WARNING', alerts[0]['state'])
    self.assertEquals('bar is rendered-bar, baz is rendered-baz', alerts[0]['text'])

    # now update only the configs and run the same alert again and check
    # for different output
    configuration = {'foo-site' :
      { 'bar': 'rendered-bar2', 'baz' : 'rendered-baz2' }
    }

    # populate the configuration cache with the initial configs
    self.__update_cluster_configuration(cluster_configuration, configuration)

    alert.collect()

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

    self.assertEquals('WARNING', alerts[0]['state'])
    self.assertEquals('bar is rendered-bar2, baz is rendered-baz2', alerts[0]['text'])
Пример #4
0
    def test_script_alert(self):
        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": "SCRIPT",
                "path": "test_script.py",
            }
        }

        # normally set by AlertSchedulerHandler
        json['source']['stacks_directory'] = os.path.join(
            'ambari_agent', 'dummy_files')
        json['source']['common_services_directory'] = os.path.join(
            'ambari_agent', 'common-services')
        json['source']['host_scripts_directory'] = os.path.join(
            'ambari_agent', 'host_scripts')

        collector = AlertCollector()
        sa = ScriptAlert(json, json['source'], MagicMock())
        sa.set_helpers(collector, {
            'foo-site/bar': 'rendered-bar',
            'foo-site/baz': 'rendered-baz'
        })
        self.assertEquals(json['source']['path'], sa.path)
        self.assertEquals(json['source']['stacks_directory'], sa.stacks_dir)
        self.assertEquals(json['source']['common_services_directory'],
                          sa.common_services_dir)
        self.assertEquals(json['source']['host_scripts_directory'],
                          sa.host_scripts_dir)

        sa.collect()

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

        self.assertEquals('WARNING', alerts[0]['state'])
        self.assertEquals('bar is rendered-bar, baz is rendered-baz',
                          alerts[0]['text'])
Пример #5
0
    def test_script_alert(self):
        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": "SCRIPT",
                "path": "test_script.py",
                "reporting": {
                    "ok": {
                        "text": "TCP OK - {0:.4f} response time on port {1}"
                    },
                    "critical": {
                        "text": "Could not load process info: {0}"
                    }
                }
            }
        }

        # normally set by AlertSchedulerHandler
        json['source']['stacks_dir'] = os.path.join('ambari_agent',
                                                    'dummy_files')

        collector = AlertCollector()
        sa = ScriptAlert(json, json['source'])
        sa.set_helpers(collector, '')
        self.assertEquals(json['source']['path'], sa.path)
        self.assertEquals(json['source']['stacks_dir'], sa.stacks_dir)

        sa.collect()

        self.assertEquals('WARNING', collector.alerts()[0]['state'])
        self.assertEquals('all is not well', collector.alerts()[0]['text'])