salt.modules.pagerduty_util

Module for manageing PagerDuty resource

configuration

This module can be used by specifying the name of a configuration profile in the minion config, minion pillar, or master config. The default configuration profile name is 'pagerduty.'

For example:

pagerduty:
    pagerduty.api_key: F3Rbyjbve43rfFWf2214
    pagerduty.subdomain: mysubdomain

For PagerDuty API details, see https://developer.pagerduty.com/documentation/rest

salt.modules.pagerduty_util.create_or_update_resource(resource_name, identifier_fields, data, diff=None, profile='pagerduty', subdomain=None, api_key=None)

create or update any pagerduty resource Helper method for present().

Determining if two resources are the same is different for different PD resource, so this method accepts a diff function. The diff function will be invoked as diff(state_information, object_returned_from_pagerduty), and should return a dict of data to pass to the PagerDuty update API method, or None if no update is to be performed. If no diff method is provided, the default behavor is to scan the keys in the state_information, comparing the matching values in the object_returned_from_pagerduty, and update any values that differ.

Examples

create_or_update_resource("user", ["id","name","email"]) create_or_update_resource("escalation_policies", ["id","name"], diff=my_diff_function)

salt.modules.pagerduty_util.delete_resource(resource_name, key, identifier_fields, profile='pagerduty', subdomain=None, api_key=None)

delete any pagerduty resource

Helper method for absent()

Example

delete_resource("users", key, ["id","name","email"]) # delete by id or name or email

salt.modules.pagerduty_util.get_escalation_policies(profile='pagerduty', subdomain=None, api_key=None)

List escalation_policies belonging to this account

CLI Example:

salt myminion pagerduty.get_escalation_policies

salt.modules.pagerduty_util.get_resource(resource_name, key, identifier_fields, profile='pagerduty', subdomain=None, api_key=None)

Get any single pagerduty resource by key.

We allow flexible lookup by any of a list of identifier_fields. So, for example, you can look up users by email address or name by calling:

get_resource('users', key, ['name', 'email'], ...)

This method is mainly used to translate state sls into pagerduty id's for dependent objects. For example, a pagerduty escalation policy contains one or more schedules, which must be passed by their pagerduty id. We look up the schedules by name (using this method), and then translate the names into id's.

This method is implemented by getting all objects of the resource type (cached into __context__), then brute force searching through the list and trying to match any of the identifier_fields. The __context__ cache is purged after any create, update or delete to the resource.

salt.modules.pagerduty_util.get_schedules(profile='pagerduty', subdomain=None, api_key=None)

List schedules belonging to this account

CLI Example:

salt myminion pagerduty.get_schedules

salt.modules.pagerduty_util.get_services(profile='pagerduty', subdomain=None, api_key=None)

List services belonging to this account

CLI Example:

salt myminion pagerduty.get_services

salt.modules.pagerduty_util.get_users(profile='pagerduty', subdomain=None, api_key=None)

List users belonging to this account

CLI Example:

salt myminion pagerduty.get_users

salt.modules.pagerduty_util.resource_absent(resource, identifier_fields, profile='pagerduty', subdomain=None, api_key=None, **kwargs)

Generic resource.absent state method. Pagerduty state modules should be a thin wrapper over this method, with a custom diff function.

This method calls delete_resource() and formats the result as a salt state return value.

Example

resource_absent("users", ["id","name","email"])

salt.modules.pagerduty_util.resource_present(resource, identifier_fields, diff=None, profile='pagerduty', subdomain=None, api_key=None, **kwargs)

Generic resource.present state method. Pagerduty state modules should be a thin wrapper over this method, with a custom diff function.

This method calls create_or_update_resource() and formats the result as a salt state return value.

Example

resource_present("users", ["id","name","email"])