将保存为csv文件的计划导入pagerduty的工具

scheduledut的Python项目详细描述


从CSV文件导入计划。目前支持每周轮班制 明细表和基于标准旋转的明细表。

用法

一。根据您的日程安排创建一个csv文件,其格式如下 类型:

Weekly Shifts:

escalation_level,user_or_team,type,day_of_week,start_time,end_time

escalation_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_time

user (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 30

Standard 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_shiftsstandard_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计划类型是必需的。

测试

  1. 创建包含命令行的文件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
    }
    
  2. config.json保存在tests目录中

  3. test_suite.py

    中运行测试套件
    python tests/test_suite.py
    

作者

卢克艾普lucas@pagerduty.com

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java搜索按钮不适用于我   java制作一个应用程序来打开您自己的文件扩展名   XMemcached中的java异步集   java无法在Android上使用HTML5 canvas touch   java是否可以用PHP为Restlet创建客户端?   java在主题中添加图标。AppCompat。光   java Safari错误,无法打开浏览器   java gson解析json值中commaseparatedvalue字符串中的项   java如何使用Quarkus在卡夫卡的同一主题中设置多个使用者   java组织。json。JSONException:在{main}()的第6个字符处的main后面应该是“:”   windowbuilder如何将Java文件导出到GATE developer   java这与安卓 studio ide问题有关,在更新我们的ide之后   java Android将活动加载到类中<?>对象   java如何在springdatajpa中使用DISTINCT、GROUP BY和ORDER BY?   使用jlink的java可复制构建