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
- saltext.pagerduty.modules.pagerduty_util.__virtual__()[source]¶
No dependencies outside of what Salt itself requires
- saltext.pagerduty.modules.pagerduty_util.get_users(profile='pagerduty', subdomain=None, api_key=None)[source]¶
List users belonging to this account
CLI Example:
salt myminion pagerduty.get_users
- saltext.pagerduty.modules.pagerduty_util.get_services(profile='pagerduty', subdomain=None, api_key=None)[source]¶
List services belonging to this account
CLI Example:
salt myminion pagerduty.get_services
- saltext.pagerduty.modules.pagerduty_util.get_schedules(profile='pagerduty', subdomain=None, api_key=None)[source]¶
List schedules belonging to this account
CLI Example:
salt myminion pagerduty.get_schedules
- saltext.pagerduty.modules.pagerduty_util.get_escalation_policies(profile='pagerduty', subdomain=None, api_key=None)[source]¶
List escalation_policies belonging to this account
CLI Example:
salt myminion pagerduty.get_escalation_policies
- saltext.pagerduty.modules.pagerduty_util.get_resource(resource_name, key, identifier_fields, profile='pagerduty', subdomain=None, api_key=None)[source]¶
Get any single pagerduty resource by key.
CLI Example:
salt myminion pagerduty.get_resource users "$key" '[name, email]'
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.
- saltext.pagerduty.modules.pagerduty_util.create_or_update_resource(resource_name, identifier_fields, data, diff=None, profile='pagerduty', subdomain=None, api_key=None)[source]¶
create or update any pagerduty resource Helper method for present().
CLI Example:
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)
- saltext.pagerduty.modules.pagerduty_util.delete_resource(resource_name, key, identifier_fields, profile='pagerduty', subdomain=None, api_key=None)[source]¶
delete any pagerduty resource
Helper method for absent()
CLI Example:
salt myminion pagerduty.delete_resource users "$key" '[id, name, email]'
Example
delete_resource(“users”, key, [“id”,”name”,”email”]) # delete by id or name or email
- saltext.pagerduty.modules.pagerduty_util.resource_present(resource, identifier_fields, diff=None, profile='pagerduty', subdomain=None, api_key=None, **kwargs)[source]¶
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.
CLI Example:
Example
resource_present(“users”, [“id”,”name”,”email”])
- saltext.pagerduty.modules.pagerduty_util.resource_absent(resource, identifier_fields, profile='pagerduty', subdomain=None, api_key=None, **kwargs)[source]¶
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.
CLI Example:
Example
resource_absent(“users”, [“id”,”name”,”email”])