- defaultTab: nodes
  description: PagerDuty Incidentに対して、自動診断と修復を実行
  executionEnabled: true
  group: Imported Jobs
  id: 77486003-5d6a-4b5d-9292-353f04f7cf0d
  loglevel: INFO
  name: R1_AutoRemediation
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: mars.*
  nodesSelectedByDefault: true
  options:
  - description: Used to pass the incident ID that will be updated.
    label: Incident ID
    name: pd_incident_id
    required: true
  - label: Auto Diag Result
    name: result_diag
    required: true
    value: SUCCESS
  - label: Auto Remediation Result
    name: result_remediation
    required: true
    value: SUCCESS
  - hidden: true
    label: API Key for PD REST API
    name: pd_api_token
    required: true
    secure: true
    storagePath: keys/workshop_api
    valueExposed: true
  - description: Email address of a PagerDuty User
    label: User Email
    name: pd_user
    required: true
    value: automation@pagerduty.com
  plugins:
    ExecutionLifecycle: {}
  runnerSelector:
    filter: WORKSHOP
    runnerFilterMode: TAGS
    runnerFilterType: TAG_FILTER_AND
  scheduleEnabled: true
  schedules: []
  sequence:
    commands:
    - description: ディスク使用量のチェック
      exec: df -h
      plugins:
        LogFilter:
        - config:
            captureMultipleKeysValues: 'false'
            hideOutput: 'false'
            logData: 'false'
            name: disk_usage
            regex: ^(.+)
          type: key-value-data-multilines
    - args: ${option.result_diag}
      description: 自動診断の実行
      fileExtension: .py
      interpreterArgsQuoted: false
      plugins:
        LogFilter:
        - config:
            invalidKeyPattern: \s|\$|\{|\}|\\
            logData: 'true'
            name: result_diag
            regex: (.*)
            replaceFilteredResult: 'false'
          type: key-value-data
      script: |-
        import sys
        # 引数が存在する場合は、引数を標準出力に返す
        if len(sys.argv) > 1:
            arg = sys.argv[1]
            print(arg)
        else:
            print("コマンドライン引数はありません。")
      scriptInterpreter: python3 ${scriptfile}
    - configuration:
        export: result_d
        group: export
        value: ${data.result_diag*}
      description: 自動診断の結果をGlobal Variableに変換
      nodeStep: false
      type: export-var
    - description: '自動診断失敗: IncidentのUrgencyをHighにし、Notesにコメントを追加'
      jobref:
        args: '-pd_comment "自動診断に失敗しました: ${data.result_diag*}\n担当者はSREチームと連携し、原因の調査にあたってください。"'
        group: Imported Jobs
        importOptions: true
        name: R2_Escalate_Incidents
        uuid: 5bc4d442-b05f-407d-82b7-b7174ef3ce2e
    - args: ${option.result_remediation}
      description: 自動復旧の実行
      fileExtension: .py
      interpreterArgsQuoted: false
      plugins:
        LogFilter:
        - config:
            invalidKeyPattern: \s|\$|\{|\}|\\
            logData: 'true'
            name: result_remediation
            regex: (.*)
            replaceFilteredResult: 'false'
          type: key-value-data
      script: |-
        import sys
        # 引数が存在する場合は、引数を標準出力に返す
        if len(sys.argv) > 1:
            arg = sys.argv[1]
            print(arg)
        else:
            print("コマンドライン引数はありません。")
      scriptInterpreter: python3 ${scriptfile}
    - configuration:
        api_token: ${option.pd_api_token}
        email: ${option.pd_user}
        incident_id: ${option.pd_incident_id}
        note: |-
          自動診断 - Disk Usage:
          ${data.disk_usage*}
      description: 自動診断の結果をNotesに追記
      errorhandler:
        exec: echo "Unable to update PagerDuty.  Please check the API Keys are correctly
          configured"
        keepgoingOnSuccess: true
      nodeStep: false
      type: pd-note-step
    - configuration:
        export: result_r
        group: export
        value: ${data.result_remediation*}
      description: 自動復旧の結果をGlobal Variableに変換
      nodeStep: false
      type: export-var
    - description: '自動復旧失敗: IncidentのUrgencyをHighにし、Notesにコメントを追加'
      jobref:
        args: '-pd_comment "自動復旧に失敗しました: ${data.result_remediation*}\nUrgencyをHighに変更し、担当者に通知します。"'
        group: Imported Jobs
        importOptions: true
        name: R2_Escalate_Incidents
        uuid: 5bc4d442-b05f-407d-82b7-b7174ef3ce2e
    - configuration:
        api_token: ${option.pd_api_token}
        email: ${option.pd_user}
        incident_id: ${option.pd_incident_id}
        resolution: prod-gw19382の再起動により、事象が解決したことを確認。IncidentのステータスをResolvedに変更します。
        status: resolved
      description: IncidentをResolveステータスに変更
      errorhandler:
        exec: echo "Unable to update PagerDuty.  Please check the API Keys are correctly
          configured"
      nodeStep: false
      type: pd-update-incident-step
    keepgoing: false
    pluginConfig:
      LogFilter:
      - config:
          color: green
          replacement: '[SECURE]'
        type: mask-passwords
      WorkflowStrategy:
        ruleset:
          rules: |-
            [1,2] run-at-start
            [3] run-after:1,2
            [4] run-after:3
            [5,6] run-after:4
            [7] run-after:5
            [8] run-after:7
            [9] run-after:8

            [4] if:export.result_d!=SUCCESS
            [5-7] if:export.result_d==SUCCESS
            [8] if:export.result_d==SUCCESS if:export.result_r!=SUCCESS
            [9] if:export.result_r==SUCCESS
    strategy: ruleset
  uuid: 77486003-5d6a-4b5d-9292-353f04f7cf0d
