如何使用restApi和python在pagerduty中创建时间表



当通过pagerduty的文档时,仍然无法理解在请求体中发送什么参数,并且在理解如何发出api请求方面也遇到了困难。如果有人能分享制作pagerduty时间表的示例代码,那将对我有很大帮助。

下面是在PagerDuty中创建时间表的示例代码。

每个列表可以有多个项目(以添加更多用户/层(

import requests

url = "https://api.pagerduty.com/schedules?overflow=false"
payload={
"schedule": {
"schedule_layers": [
{
"start": "<dateTime>", # Start Time of layer |  "start": "2021-01-01T00:00:00+05:30", 
"users": [
{
"user": {
"id": "<string>",        # ID of user to add in layer  
"summary": "<string>",   
"type": "<string>",      # "type": "user"
"self": "<url>",
"html_url": "<url>"
}
}
],
"rotation_virtual_start": "<dateTime>",   # Start of layer  | "rotation_virtual_start": "2021-01-01T00:00:00+05:30",
"rotation_turn_length_seconds": "<integer>", # Layer rotation, for multiple user switching | "rotation_turn_length_seconds": <seconds>,
"id": "<string>",      # Auto-generated. Only needed if you want update and existing Schedule Layer
"end": "<dateTime>",   # End Time of layer |  "end": "2021-01-01T00:00:00+05:30",
"restrictions": [
{
"type": "<string>", # To restrict shift to certain timings Weekly daily etc | "type": "daily_restriction",
"duration_seconds": "<integer>", # Duration of layer | "duration_seconds": "300"
"start_time_of_day": "<partial-time>", #Start time of layer | "start_time_of_day": "00:00:00",
"start_day_of_week": "<integer>" 
}
],
"name": "<string>", # Name to give Layer 
}
]
"time_zone": "<activesupport-time-zone>",  # Timezone to set for layer and its timings | "time_zone": "Asia/Kolkata",
"type": "schedule",
"name": "<string>", # Name to give Schedule 
"description": "<string>",# Description to give Schedule 
"id": "<string>",      # Auto-generated. Only needed if you want update and existing Schedule Layer
}
}
headers = {
'Authorization': 'Token token=<Your token here>',
'Accept': 'application/vnd.pagerduty+json;version=2',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)

最好的方法是获取PagerDuty的邮递员集合,并根据您的喜好编辑请求。一旦你得到了成功的回复,就可以使用poster的内置功能将其转换为代码。

使用PagerDuty API进行调度并不容易。创建新的时间表是可以的,但如果您决定更新时间表,这绝对不是小事。你可能会遇到一堆限制:每层的限制数量,必须重用当前层,等等。

作为选项,您可以使用python库pdschedulinghttps://github.com/skrypka/pdscheduling

相关内容

  • 没有找到相关文章

最新更新