# ジョブ更新ポリシータイプ

<figure><img src="/files/Men8WaNXrilZLCzAIKXV" alt=""><figcaption></figcaption></figure>

**ジョブ更新**ポリシーを使うと、エンドポイント上の**ジョブ定義**を一元的に配布・更新・削除できます。

***

### 仕組み (概要)

エージェントは、`PolicyType` が **`"JobUpdate"`** のポリシーを処理します。`Extension` の内容に応じて、エンドポイント上の `Jobs/{JobId}.json` のジョブ定義を追加・更新・削除します。

### 手順: Update Jobsポリシーの作成 (高度なJSONから)

{% stepper %}
{% step %}
**エンドポイント特権マネージャー** → **\[ポリシー]** に移動

<figure><img src="/files/uq52MPoT1AUq5wcPGC2u" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**\[ポリシーの作成]** ボタンをクリック

ポリシー作成用のモーダルが開きます。

<figure><img src="/files/Hn1TQcU2TBuyR6pPYuN9" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**ポリシー属性の定義**

新しいポリシーには、適切で分かりやすい名前を付けます。

新規ポリシーでは、UIに表示されている**既存のポリシータイプのいずれか**を選びます (あくまで作成時のテンプレートであり、**ジョブ更新**は後述のJSONで指定します)。

ステータスを選びます。初めてポリシーを用意するときは、**監視**を推奨します。

**\[コントロールを追加]** をクリックしてコントロールを1つ以上追加し、新しいポリシーに含めたいコントロールを選びます。

ユーザーグループ、マシンコレクション、アプリケーションコレクションを指定します。
{% endstep %}

{% step %}
**ポリシーの適用対象の設定**

UIで、コレクション/ユーザー/マシン/アプリ/プラットフォームなどから、必要な**適用対象**を設定し、ポリシーの適用先を決めます。
{% endstep %}

{% step %}
**Advanced Mode** (JSONビュー) を開く

ポリシーフォーム左下の **\[Advanced Mode]** のリンクをクリックして開きます。

<figure><img src="/files/NgeQ2U57RyINTbb1KkEx" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**JSONでポリシータイプを再定義**

`PolicyType` を **`"JobUpdate"`** に設定します。
{% endstep %}

{% step %}
**Extension**フィールドの定義

このドキュメントの[必須の拡張フィールド](#required-extension-fields)に沿って、`Extension` の各フィールドを設定します。
{% endstep %}

{% step %}
**ポリシーを保存**
{% endstep %}
{% endstepper %}

### 必須の拡張フィールド

* `Extension.JobId`: ジョブ識別子。エージェントが `Jobs/{JobId}.json` を書き込み/削除するときのキー
* `Extension.Action`: `"Add"`、`"Update"`、または `"Delete"`
* `Extension.JobJson`: 追加・更新の際に必須。削除の際は省略

**IDの要件:** `JobJson` 内の `id` は、必ず `JobId` と同じ値にします。

***

## JSONの例

#### 例1: ジョブの追加 (JobUpdate / Action=Add)

```
{
  "PolicyName": "Update Jobs - Add Maintenance Job",
  "PolicyType": "JobUpdate",
  "PolicyId": "REPLACE_WITH_ID",
  "Status": "on",
  "Actions": {
    "OnSuccess": {
      "Controls": [
        "NOTIFY"
      ]
    },
    "OnFailure": {
      "Command": ""
    }
  },
  "NotificationMessage": "A job was added to this endpoint via policy.",
  "NotificationRequiresAcknowledge": false,
  "RiskLevel": 20,
  "Operator": "And",
  "Rules": [
    {
      "RuleName": "UserCheck",
      "ErrorMessage": "This user is not included in this policy",
      "RuleExpressionType": "BuiltInAction",
      "Expression": "CheckUser()"
    },
    {
      "RuleName": "MachineCheck",
      "ErrorMessage": "This Machine is not included in this policy",
      "RuleExpressionType": "BuiltInAction",
      "Expression": "CheckMachine()"
    }
  ],
  "UserCheck": [],
  "MachineCheck": [],
  "ApplicationCheck": [],
  "DayCheck": [],
  "DateCheck": [],
  "TimeCheck": [],
  "CertificationCheck": [],
  "Extension": {
    "JobId": "my-maintenance-job",
    "Action": "Add",
    "JobJson": "{\n  \"id\": \"my-maintenance-job\",\n  \"name\": \"My Maintenance Job\",\n  \"description\": \"Runs periodic maintenance actions.\",\n  \"enabled\": true,\n  \"schedule\": {\n    \"type\": \"interval\",\n    \"minutes\": 60\n  },\n  \"tasks\": [\n    {\n      \"type\": \"command\",\n      \"name\": \"Example Task\",\n      \"command\": \"echo Maintenance job ran\"\n    }\n  ]\n}"
  }
}
```

**注**

* `Extension.JobJson` は、ジョブ定義のJSONを1本の**文字列**として渡すフィールドです (中身はジョブJSONの全体)。
* 内側のジョブJSONに `"id": "my-maintenance-job"` を含め、`JobId` と一致させてください。

***

#### 例2: 既存ジョブの更新 (JobUpdate / Action=Update)

```
{
  "PolicyName": "Update Jobs - Update Maintenance Job",
  "PolicyType": "JobUpdate",
  "PolicyId": "REPLACE_WITH_ID",
  "Status": "on",
  "Actions": {
    "OnSuccess": {
      "Controls": [
        "NOTIFY"
      ]
    },
    "OnFailure": {
      "Command": ""
    }
  },
  "NotificationMessage": "A job was updated on this endpoint via policy.",
  "NotificationRequiresAcknowledge": false,
  "RiskLevel": 20,
  "Operator": "And",
  "Rules": [
    {
      "RuleName": "UserCheck",
      "ErrorMessage": "This user is not included in this policy",
      "RuleExpressionType": "BuiltInAction",
      "Expression": "CheckUser()"
    },
    {
      "RuleName": "MachineCheck",
      "ErrorMessage": "This Machine is not included in this policy",
      "RuleExpressionType": "BuiltInAction",
      "Expression": "CheckMachine()"
    }
  ],
  "UserCheck": [],
  "MachineCheck": [],
  "ApplicationCheck": [],
  "DayCheck": [],
  "DateCheck": [],
  "TimeCheck": [],
  "CertificationCheck": [],
  "Extension": {
    "JobId": "my-maintenance-job",
    "Action": "Update",
    "JobJson": "{\n  \"id\": \"my-maintenance-job\",\n  \"name\": \"My Maintenance Job\",\n  \"description\": \"Runs periodic maintenance actions (updated schedule).\",\n  \"enabled\": true,\n  \"schedule\": {\n    \"type\": \"interval\",\n    \"minutes\": 30\n  },\n  \"tasks\": [\n    {\n      \"type\": \"command\",\n      \"name\": \"Example Task\",\n      \"command\": \"echo Maintenance job ran (updated)\"\n    }\n  ]\n}"
  }
}
```

**注**

* 更新では通常、`JobJson` で渡した内容によりジョブファイル全体が置き換わるため、ジョブスキーマで必要なフィールドはすべて含めます。

***

#### 例3: ジョブの削除 (JobUpdate / Action=Delete)

```
{
  "PolicyName": "Update Jobs - Delete Maintenance Job",
  "PolicyType": "JobUpdate",
  "PolicyId": "REPLACE_WITH_ID",
  "Status": "on",
  "Actions": {
    "OnSuccess": {
      "Controls": [
        "NOTIFY"
      ]
    },
    "OnFailure": {
      "Command": ""
    }
  },
  "NotificationMessage": "A job was deleted from this endpoint via policy.",
  "NotificationRequiresAcknowledge": false,
  "RiskLevel": 20,
  "Operator": "And",
  "Rules": [
    {
      "RuleName": "UserCheck",
      "ErrorMessage": "This user is not included in this policy",
      "RuleExpressionType": "BuiltInAction",
      "Expression": "CheckUser()"
    },
    {
      "RuleName": "MachineCheck",
      "ErrorMessage": "This Machine is not included in this policy",
      "RuleExpressionType": "BuiltInAction",
      "Expression": "CheckMachine()"
    }
  ],
  "UserCheck": [],
  "MachineCheck": [],
  "ApplicationCheck": [],
  "DayCheck": [],
  "DateCheck": [],
  "TimeCheck": [],
  "CertificationCheck": [],
  "Extension": {
    "JobId": "my-maintenance-job",
    "Action": "Delete"
  }
}
```

**注**

* `Delete` のときは `JobJson` を書かないでください。

### 運用でよく変える項目

* `PolicyId`: UIで採番された値のままにします。
* `Status`: 展開状況に応じて `"on"` / `"off"` を切り替えます。
* `UserCheck` / `MachineCheck`: コンソールの通常の適用対象と同じ要領で配列を埋めます。
* `Extension.JobId`: ファイル名のキー (エンドポイント上では `Jobs/{JobId}.json` になります)。
* `Extension.JobJson`: 追加・更新用にジョブ定義全体を文字列化したもの。

### エンドポイントでの検証

* **追加・更新**の際は、`Jobs/{JobId}.json` が存在し、渡したジョブJSONの内容と一致していることを確認します。
* **削除**の際は、`Jobs/{JobId}.json` がなくなっていることを確認します。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/endpoint-privilege-manager/policies/policy-types/advanced-policy-types/update-jobs-policy-type.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
