将保存为csv文件的计划导入pagerduty的工具
scheduledut的Python项目详细描述
从CSV文件导入计划。目前支持每周轮班制 明细表和基于标准旋转的明细表。
用法
一。根据您的日程安排创建一个csv文件,其格式如下 类型:
Weekly Shifts:
escalation_level,user_or_team,type,day_of_week,start_time,end_timeescalation_level (int): Level to place user/team on the escalation policy
user_or_team (str): The name/email of the user/team
type (str): Must be one of user, team
day_of_week (str or int): Must be one of 0, 1, 2, 3, 4, 5, 6, sunday, monday, tuesday, wednesday, thursday, friday, saturday, weekday, weekdays, weekend, weekends, all
start_time (str): Start time of the shift for that day (i.e. 13:00)
end_time (str): End time of the shift for that day (i.e. 21:00)
Standard Rotation:
user,layer,layer_name,rotation_type,shift_length,shift_type,handoff_day,handoff_time,restriction_start_day,restriction_start_time,restriction_end_date,restriction_end_timeuser (str): The name/email of the user
layer (int): The schedule layer
layer_name (str): The name of the layer
rotation_type (str): The type of rotation. Can be one of daily, weekly, custom.
shift_length (int): Length of the on-call shift in a ^{tt1}$ rotation
shift_type (str): The unit of measure for the ^{tt2}$. Can be one of hours, days, weeks.
handoff_day (str or int): The day of the week to handoff the on-call shift. Can be one of 0, 1, 2, 3, 4, 5, 6, monday, tuesday, wednesday, thursday, friday, saturday, sunday
handoff_time (str):The time of day to handoff the shift (i.e. 08:00)
restriction_start_day (str): Day of the week to start the restriction. Can be one of 0, 1, 2, 3, 4, 5, 6, monday, tuesday, wednesday, thursday, friday, saturday, sunday
restriction_start_time (str): Time of day to start the restriction (i.e. 08:00)
restriction_end_date (str): Day of the week to end the restriction. Can be one of 0, 1, 2, 3, 4, 5, 6, monday, tuesday, wednesday, thursday, friday, saturday, sunday
restriction_end_time (str): Time of day to end the restriction (i.e. 17:00)
2.将所有csv文件保存到一个目录中
三。如果从命令行运行,请使用以下命令行参数执行import_schedules.py脚本 您的日程类型:
Weekly Shifts:
./scheduleduty/scheduleduty.py --schedule-type weekly_shifts --csv-dir examples/weekly_shifts --api-key EXAMPLE_TOKEN --base-name "Weekly Shifts" --level-name Level --multiple-name Multi --start-date 2017-01-01 --end-date 2017-02-01 --time-zone UTC --num-loops 1 --escalation-delay 30Standard Rotation:
./scheduleduty/scheduleduty.py --schedule-type standard_rotation --csv-dir examples/standard_rotation --api-key EXAMPLE_TOKEN --base-name "Standard Rotation" --start-date 2017-01-01 --end-date 2017-02-01 --time-zone UTC
四。如果导入到脚本中,请使用Import类中的execute函数导入计划:
Weekly Shifts:
from scheduleduty import scheduleduty importer = scheduleduty.Import("weekly_shifts","./examples/weekly_shifts","EXAMPLE_TOKEN","Weekly Shifts","Level","Multi","2017-01-01","2017-02-01","UTC",1,30) importer.execute()Standard Rotation:
from scheduleduty import scheduleduty importer = scheduleduty.Import("standard_rotation","./examples/standard_rotation","EXAMPLE_TOKEN","Standard Rotation",None,None,"2017-01-01","2017-02-01","UTC",None,None) importer.execute()
参数
--schedule-type:正在上载的计划类型。必须是weekly_shifts,standard_rotation之一。
--csv-dir:要导入pagerduty的所有csv所在目录的路径。所有计划类型都需要。
--api-key:pagerduty v2 rest api令牌。所有计划类型都需要。
--base-name:要添加的升级策略或计划的名称,以及添加到升级策略的每个计划的基名称。所有计划类型都需要。
--level-name:要由级别号的整数值追加的每个新升级策略级别的基名称。对于weekly_shifts计划类型是必需的。
--multiple-name:在同一升级策略级别上的每个计划的基名称,将由计划号的整数值追加。对于weekly_shifts计划类型是必需的。
--start-date:计划的ISO 8601格式的开始日期。目前只支持yyyy-mm-dd格式的日期。所有计划类型都需要。
--end-date:计划的ISO 8601格式结束日期。目前只支持yyyy-mm-dd格式的日期。对于所有计划类型都是可选的。
--time-zone:此计划的时区。必须是IANA时区数据库中的时区之一。所有计划类型都需要。
--num-loops:循环通过升级策略的次数。对于weekly_shifts计划类型是必需的。
--escalation-delay:将事件升级到下一级别之前要等待的分钟数。对于weekly_shifts计划类型是必需的。
测试
创建包含命令行的文件config.json。 测试参数:
{ "api_key": "EXAMPLE_KEY", "base_name": "Weekly Shifts", "level_name": "Level", "multi_name": "Multi", "start_date": "2017-01-01", "end_date": null, "time_zone": "UTC", "num_loops": 1, "escalation_delay": 30 }
将config.json保存在tests目录中
在test_suite.py:
中运行测试套件python tests/test_suite.py