def create_incident(appDict):
    """
    logic to create a pagerduty incident
    :param appDict:
    :return: the json string from the PD API
    """

    payload = build_incident_payload(appDict)
    LOG.debug(payload)

    # build url
    session = APISession(appDict['api_token'],
                         name=appDict['resilient_client'],
                         default_from=appDict['from_email'])
    resp = session.post(INCIDENT_FRAGMENT, payload)
    return resp.json()
def create_note(appDict, incident_id, note):
    """
    Create a PagerDuty note
    :param appDict:
    :param incident_id:
    :param note:
    :return: the json string from the PD API
    """
    payload = build_note_payload(note)

    # build url
    url = NOTE_FRAGMENT.format(incident_id)

    session = APISession(appDict['api_token'],
                         name=appDict['resilient_client'],
                         default_from=appDict['from_email'])
    resp = session.post(url, payload)
    return resp.json()
Ejemplo n.º 3
0
    def create(self, api_token, log_file):
        # basicConfig(filename=log_file, level=DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
        #             datefmt='%Y-%m-%d %H:%M:%S')

        lf = open(log_file, 'a+')
        data = {
            "condition": self.condition,
            "actions": [[self.actions, self.service_id]]
        }

        print("\n[%s] [%s]: Event Rules Before Payload: %s" %
              (datetime.now(), 'Info', data))
        # print(data)
        try:

            session = APISession(api_token)
            provision_event_rules = session.post("/event_rules", json=data)
            lf.write(
                "\n[%s] [%s]: ===== The provisioned event rule was: =====" %
                (datetime.now(), 'Info'))

            self.payload = provision_event_rules.json()
            lf.write("\n[%s] [%s]: Event Rules Payload: %s" %
                     (datetime.now(), 'Info', self.payload))
            print("\n[%s] [%s]: Event Rules Payload: %s" %
                  (datetime.now(), 'Info', self.payload))
            self.id = self.payload["id"]
            lf.write("\n[%s] [%s]: EVent Rules ID: %s" %
                     (datetime.now(), 'Info', self.id))

            lf.write(
                "\n[%s] [%s]: =================== EVENT RULE CREATED ===================="
                % (datetime.now(), 'Info'))
        except PDClientError as e:
            lf.write("\n[%s] [%s]: %s" % (datetime.now(), 'Error', e.response))
            lf.write("\n[%s] [%s]: %s" %
                     (datetime.now(), 'Error', e.response.url))
            lf.write("\n[%s] [%s]: %s" %
                     (datetime.now(), 'Error', e.response.text))
            lf.write("\n[%s] [%s]: %s" %
                     (datetime.now(), 'Error', print_exc()))
        lf.close()
Ejemplo n.º 4
0
    def assign_dependent_services(self, user_token, service_id, log_file):
        lf = open(log_file, 'a+')

        try:
            session = APISession(user_token)
            data = {
                "relationships": [{
                    "supporting_service": {
                        "id": self.id,
                        "type": "business_service"
                    },
                    "dependent_service": {
                        "id": service_id,
                        "type": "service"
                    }
                }]
            }
            lf.write(
                "\n[%s] [%s]: ===============Associating Dependent Services=================="
                % (datetime.now(), 'Info'))
            lf.write("\n[%s] [%s]: TESTING TECH SVC: %s" %
                     (datetime.now(), 'Info', data))
            assign_tech_services = session.post(
                "/service_dependencies/associate", json=data)

            self.payload = assign_tech_services
            lf.write("\n[%s] [%s]: Payload: %s" %
                     (datetime.now(), 'Info', self.payload))

            lf.write(
                "\n[%s] [%s]: =================== DEPENDENT SERVICES ASSOCIATED ===================="
                % (datetime.now(), 'Info'))
        except PDClientError as e:
            lf.write("\n[%s] [%s]: %s" % (datetime.now(), 'Error', e.response))
            lf.write("\n[%s] [%s]: %s" %
                     (datetime.now(), 'Error', e.response.url))
            lf.write("\n[%s] [%s]: %s" %
                     (datetime.now(), 'Error', e.response.text))
            lf.write("\n[%s] [%s]: %s" %
                     (datetime.now(), 'Error', print_exc()))
Ejemplo n.º 5
0
    def create(self, user_token, log_file):
        # basicConfig(filename=log_file, level=DEBUG, format='%(asctime)s %(levelname)-8s %(message)s',
        #             datefmt='%Y-%m-%d %H:%M:%S')

        lf = open(log_file, 'a+')

        data = {"name": self.name, "description": self.description, "aggregation_types": self.aggregation_types,
                "precision": self.precision, "unit_short": self.unit_short, "y_range_max": self.y_range_max,
                "y_range_min": self.y_range_min}
        try:
            session = APISession(user_token)
            provision_impact_metric = session.post("/business_impact_metrics", json={'business_impact_metric': data})
            lf.write("\n[%s] [%s]: ===== The provisioned business impact metric was: =====" % (datetime.now(), 'Info'))
            lf.write("\n[%s] [%s]: Business Impact Metrics response: %s" % (datetime.now(), 'Info', str(provision_impact_metric.json())))
            self.payload = provision_impact_metric.json()
            self.id = provision_impact_metric.json()["business_impact_metric"]["id"]
            self.provisioned_name = provision_impact_metric.json()["business_impact_metric"]["name"]
            lf.write("\n[%s] [%s]: =================== BUSINESS IMPACT METRIC CREATED ====================" % (datetime.now(), 'Info'))
        except PDClientError as e:
            lf.write("\n[%s] [%s]: %s" % (datetime.now(), 'Error', e.response))
            lf.write("\n[%s] [%s]: %s" % (datetime.now(), 'Error', e.response.url))
            lf.write("\n[%s] [%s]: %s" % (datetime.now(), 'Error', e.response.text))
            lf.write("\n[%s] [%s]: %s" % (datetime.now(), 'Error', print_exc()))
        lf.close()