def createOpsgenie(self):
     api_key = self.getOpsgenieKey()
     self.conf = self.conf = opsgenie_sdk.configuration.Configuration()
     self.conf.api_key['Authorization'] = api_key
     self.api_client = opsgenie_sdk.api_client.ApiClient(
         configuration=self.conf)
     self.alert_api = opsgenie_sdk.AlertApi(api_client=self.api_client)
     body = opsgenie_sdk.CreateAlertPayload(
         message='AirFlow Job: activision_file_drop is failed',
         description=
         'Please check the activision_file_drop dag logs in the airflow',
         responders=[{
             'name': 'DevOps',
             'type': 'team'
         }],
         priority='P3')
     try:
         create_response = self.alert_api.create_alert(
             create_alert_payload=body)
         logger.info(
             "Sent opsgenie notification!. Response Code - {}".format(
                 create_response))
         time.sleep(3)
         alertID = create_response.id
         success_response = self.alert_api.add_attachment(
             identifier=alertID, file='activision_report.html')
         return create_response
     except opsgenie_sdk.ApiException as err:
         logger.error(
             "Exception when calling Opsgenie AlertApi->create_alert: {}".
             format(err))
         raise err
Ejemplo n.º 2
0
 def create(self):
     body = opsgenie_sdk.CreateAlertPayload(
         message='Sample',
         alias='python_sample',
         description='Sample of SDK v2',
         responders=[{
             'name': 'SampleTeam',
             'type': 'team'
         }],
         visible_to=[{
             'name': 'Sample',
             'type': 'team'
         }],
         actions=['Restart', 'AnExampleAction'],
         tags=['OverwriteQuietHours'],
         details={
             'key1': 'value1',
             'key2': 'value2'
         },
         entity='An example entity',
         priority='P3')
     try:
         create_response = self.alert_api.create_alert(
             create_alert_payload=body)
         print(create_response)
         return create_response
     except opsgenie_sdk.ApiException as err:
         print("Exception when calling AlertApi->create_alert: %s\n" % err)
Ejemplo n.º 3
0
    def setUp(self) -> None:
        self.test_api_key = 'test api key'
        self.test_eu_host_true = True
        self.test_eu_host_false = False
        self.test_system_name = 'test system'
        self.test_percentage_usage = 50
        self.test_panic_severity = 'WARNING'
        self.test_last_monitored = 45.5
        self.test_parent_id = 'chain123'
        self.test_system_id = 'system123'
        self.test_alert = OpenFileDescriptorsIncreasedAboveThresholdAlert(
            self.test_system_name, self.test_percentage_usage,
            self.test_panic_severity, self.test_last_monitored,
            self.test_panic_severity, self.test_parent_id, self.test_system_id
        )
        self.test_opsgenie_severity = OpsgenieSeverities.WARNING
        self.test_alias = self.test_alert.alert_code.value

        self.test_alert_create_payload = opsgenie_sdk.CreateAlertPayload(
            message=self.test_alert.alert_code.name,
            description="Message: {} \n Triggered at: {}".format(
                self.test_alert.message, datetime.fromtimestamp(
                    self.test_alert.timestamp)),
            priority=self.test_opsgenie_severity.value,
            source=self.test_alert.origin_id, alias=self.test_alias
        )

        self.test_opsgenie_api_eu = OpsgenieApi(self.test_api_key,
                                                self.test_eu_host_true)
        self.test_opsgenie_api_non_eu = OpsgenieApi(self.test_api_key,
                                                    self.test_eu_host_false)
Ejemplo n.º 4
0
 def create_alert_exception(self):
     # create an instance of the API class
     alert_api = opsgenie_sdk.AlertApi(opsgenie_sdk.ApiClient(self.configuration))
     # CreateAlertPayload | Request payload of created alert
     create_alert_payload = opsgenie_sdk.CreateAlertPayload(
         message="test-alert-exception", description="Zero Division exception occured in the division operation"
     )
     # create alert
     api_response = alert_api.create_alert(create_alert_payload)
     pprint(api_response)
Ejemplo n.º 5
0
 def create_alert(self, alert_name: str, alert_message: str,
                  severity: OpsgenieSeverities, origin: str,
                  timestamp: float, alias: str = None) \
         -> Optional[SuccessResponse]:
     payload = opsgenie_sdk.CreateAlertPayload(
         message=alert_name,
         description="Message: {} \n Triggered at: {}".format(
             alert_message, datetime.fromtimestamp(timestamp)),
         priority=severity.value,
         source=origin,
         alias=alias)
     return self._alert_api.create_alert(create_alert_payload=payload)
Ejemplo n.º 6
0
    def create_alert(self, weight):
        body = opsgenie_sdk.CreateAlertPayload(message='Uploaded weight',
                                               alias='uploaded_weight',
                                               description=weight,
                                               priority='P5')

        try:
            create_response = self.alert_api.create_alert(
                create_alert_payload=body)
            print(create_response)
            return create_response
        except opsgenie_sdk.ApiException as err:
            print("Exception when calling AlertApi->create_alert: %s\n" % err)
Ejemplo n.º 7
0
    def create_alert(self):
        body = opsgenie_sdk.CreateAlertPayload(
            message="Example Closed",
            description="Creating example alert",
            priority='P5',
        )

        try:
            create_response = self.alert_api.create_alert(
                create_alert_payload=body)
            print(create_response)
            return create_response
        except ApiException as err:
            print("Exception when calling AlertApi->create_alert: %s\n" % err)
Ejemplo n.º 8
0
 def create(self, incident_id, incident_summary, team):
     body = opsgenie_sdk.CreateAlertPayload(
         message=f'{incident_id} - {incident_summary}',
         alias='{team}-{incident_id}',
         description=f'{settings.SITE_URL}/incident/{incident_id}/',
         responders=[{
             'name': team,
             'type': 'team'
           }],
         priority='P1'
       )
     try:
         create_response = self.alert_api.create_alert(create_alert_payload=body)
         print(create_response)
         return create_response
     except opsgenie_sdk.ApiException as err:
         print("Exception when calling AlertApi->create_alert: %s\n" % err)