def update_incident(appDict, incident_id, status, priority, resolution):
    """
    update an incident. Used to raise the severity or to close the Incident
    :param appDict:
    :param incident_id:
    :param status:
    :param priority:
    :param resolution:
    :return: the json string from the PD API
    """
    payload = build_update_payload(appDict, status, priority, resolution)

    # build url
    url = UPDATE_FRAGMENT.format(incident_id)
    session = APISession(appDict['api_token'],
                         name=appDict['resilient_client'],
                         default_from=appDict['from_email'])
    resp = session.put(url, payload)
    return resp.json()
예제 #2
0
    def assign_impact_metrics(self, user_token, impact_id, 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+')

        try:
            session = APISession(user_token)
            data = {
                "business_services": [{
                    "id": self.id,
                    "type": "business_service_reference"
                }]
            }
            lf.write(
                "\n[%s] [%s]: ===============Associating Impact Metrics=================="
                % (datetime.now(), 'Info'))
            lf.write("\n[%s] [%s]: Payload before POST: %s" %
                     (datetime.now(), 'Info', data))

            assign_impect_metric = session.put(
                "business_services/impact_metrics_associations/" + impact_id,
                json=data)
            lf.write("\n[%s] [%s]: Metrics value: %s" %
                     (datetime.now(), 'Info', assign_impect_metric.json()))
            self.payload = assign_impect_metric.json()
            lf.write(
                "\n[%s] [%s]: =================== IMPACT METRIC 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()))

        lf.close()
예제 #3
0
    def assign_supporting_services_old(self, user_token, supporting_services,
                                       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+')

        try:
            session = APISession(user_token)
            data = {
                "business_service": {
                    "supporting_services": supporting_services
                }
            }
            lf.write(
                "\n[%s] [%s]: ===============Associating Supporting Services=================="
                % (datetime.now(), 'Info'))
            lf.write("\n[%s] [%s]: TESTING TECH SVC: %s" %
                     (datetime.now(), 'Info', data))
            assign_tech_services = session.put("/business_services/" + self.id,
                                               json=data)
            # print(assign_tech_services.json())
            self.payload = assign_tech_services.json()
            lf.write("\n[%s] [%s]: Payload: %s" %
                     (datetime.now(), 'Info', self.payload))
            # self.supporting_services = self.payload["supporting_services"]
            lf.write(
                "\n[%s] [%s]: =================== SUPPORTING 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()))