Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_profiler_key(self):
sess = pdpyras.APISession('token')
self.assertEqual(
'post:users/{id}/contact_methods/{index}',
sess.profiler_key(
'POST',
'https://api.pagerduty.com/users/PCWKOPZ/contact_methods'
)
def mass_update_incidents(args):
session = pdpyras.APISession(args.api_key,
default_from=args.requester_email)
if args.user_id:
PARAMETERS['user_ids[]'] = args.user_id.split(',')
print("Acting on incidents assigned to user(s): "+args.user_id)
if args.service_id:
PARAMETERS['service_ids[]'] = args.service_id.split(',')
print("Acting on incidents corresponding to service ID(s): " +
args.service_id)
if args.action == 'resolve':
PARAMETERS['statuses[]'] = ['triggered', 'acknowledged']
print("Resolving incidents")
elif args.action == 'acknowledge':
PARAMETERS['statuses[]'] = ['triggered']
print("Acknowledging incidents")
if args.date_range is not None:
sinceuntil = args.date_range.split(',')
sys.stdout.write("User name: {}\n".format(member['user']['summary']))
sys.stdout.write("Team role: {}\n".format(member['role']))
sys.stdout.write("-----\n")
except pdpyras.PDClientError as e:
print("Could not get team members for team {} {}".format(team_name, team_id))
raise e
if __name__ == '__main__':
ap = argparse.ArgumentParser(description="Retrieves team roles for"
"users in a PagerDuty account")
ap.add_argument('-k', '--api-key', required=True, help="REST API key")
ap.add_argument('-c', '--comma-separated', required=False, default=False, action='store_true', help="Format output separated by commas")
args = ap.parse_args()
session = pdpyras.APISession(args.api_key)
get_teams(session, args.comma_separated)
def find_element_by_name(appDict, element, name):
"""
find the internal id for a pagerduty element (policy, service, priority, etc.)
:param appDict:
:param element: escalation_policies, service, priority, etc.
:param name:
:return: id of policy or None
"""
session = APISession(appDict['api_token'])
try:
rtn_element = session.find(element, name.strip().lower())
LOG.debug(rtn_element)
return rtn_element['id'] if rtn_element else None
except PDClientError as err:
LOG.error(str(err))
return None
sys.stdout.write('%s %s'%(contact_method['country_code'],
contact_method['address']))
elif 'email' in contact_method['type']:
sys.stdout.write("Email: ")
sys.stdout.write(contact_method['address'])
elif 'push_notification' in contact_method['type']:
sys.stdout.write("Push: ")
sys.stdout.write(contact_method['label'])
sys.stdout.write("\n")
if __name__ == '__main__':
ap = argparse.ArgumentParser(description="Retrieves contact info for all "
"users in a PagerDuty account")
ap.add_argument('-k', '--api-key', required=True, help="REST API key")
args = ap.parse_args()
session = pdpyras.APISession(args.api_key)
get_users(session)
ap.add_argument('-n', '--dry-run', default=False, action='store_true',
help="Don't actually make changes, but print out each change that "
"would be made.")
ap.add_argument('-c', '--contact-methods', default=False,
action='store_true', help="Update email contact methods as well as "
"login email addresses.")
args = ap.parse_args()
if args.all_users and not (args.find_pattern and args.replacement_pattern)\
or args.query and not args.replacement_pattern:
print("There is insufficient information to determine what you want to "
"do.\n- If using the --all-users option, you must also provide "
"--find-regex and --replace-regex to specify how the emails should "
"be updated\n- If using --query, you must at least provide "
"--replace-regex")
return
session = pdpyras.APISession(args.api_key)
replace_emails(args)
"address of the user who is going on vacation.")
ap.add_argument('-u', '--substitute', required=True, help="Login email "
"address of the user who is covering the shifts of the vacationing "
"user.")
ap.add_argument('-k', '--api-key', required=True, help="PagerDuty REST API "
"key to use for operations.")
ap.add_argument('-s', '--start', required=True, help="Start date of the "
"vacation.")
ap.add_argument('-e', '--end', required=True, help="End date of the "
"vacation.")
ap.add_argument('-c' , '--schedules', default=[], action='append',
help="IDs of schedules in which to create overrides. If unspecified, "
"all schedules will be included.")
args = ap.parse_args()
session = pdpyras.APISession(args.api_key)
vacationing_user = session.find('users', args.vacationer, attribute='email')
replacement_user = session.find('users', args.substitute, attribute='email')
if None in (vacationing_user, replacement_user):
print("Invalid login email specified for the vacationing user and/or "
"substitute user.")
return
schedules = args.schedules
if not args.schedules:
print("Getting schedules...")
schedules = [s['id'] for s in session.iter_all('schedules')]
print("Looking for shifts that will require coverage...")
shifts = find_shifts(session, vacationing_user['id'], args.start, args.end,
schedules)
for dates, schedule in shifts.items():
start, end = dates
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()