0

当通过 pagerduty 的文档但仍然无法理解在请求正文中发送哪些参数并且在理解如何发出 api 请求时遇到了麻烦。如果有人可以分享有关制定 pagerduty 计划的示例代码,这将有所帮助我很多。

4

2 回答 2

0

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

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

于 2021-06-29T17:44:45.007 回答
0

下面是在 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 的邮递员集合并根据您的喜好编辑请求。获得成功响应后,使用邮递员的内置功能将其转换为代码。

于 2021-03-30T18:18:04.813 回答