示例#1
0
 def test_api_key_required(self, mock_get_connection, mock_initialize):
     mock_get_connection.return_value = Connection()
     with pytest.raises(AirflowException) as ctx:
         DatadogHook()
     assert str(
         ctx.value
     ) == 'api_key must be specified in the Datadog connection details'
示例#2
0
    def poke(self, context: 'Context') -> bool:
        # This instantiates the hook, but doesn't need it further,
        # because the API authenticates globally (unfortunately),
        # but for airflow this shouldn't matter too much, because each
        # task instance runs in its own process anyway.
        DatadogHook(datadog_conn_id=self.datadog_conn_id)

        response = api.Event.query(
            start=self.from_seconds_ago,
            end=self.up_to_seconds_from_now,
            priority=self.priority,
            sources=self.sources,
            tags=self.tags,
        )

        if isinstance(response, dict) and response.get('status', 'ok') != 'ok':
            self.log.error("Unexpected Datadog result: %s", response)
            raise AirflowException("Datadog returned unexpected result")

        if self.response_check:
            # run content check on response
            return self.response_check(response)

        # If no check was inserted, assume any event that matched yields true.
        return len(response) > 0
示例#3
0
 def setUp(self, mock_get_connection, mock_initialize):
     mock_get_connection.return_value = Connection(
         extra=json.dumps({
             'app_key': APP_KEY,
             'api_key': API_KEY,
         }))
     self.hook = DatadogHook()
示例#4
0
 def test_api_key_required(self, mock_get_connection, mock_initialize):
     mock_get_connection.return_value = Connection()
     with self.assertRaises(AirflowException) as ctx:
         DatadogHook()
     self.assertEqual(
         str(ctx.exception),
         'api_key must be specified in the Datadog connection details')