このページのトピック
予約されたタスクを使用した保護の維持
予約タスクを使用すると、特定の Workload Security タスクをスケジュールに従って自動的に実行できます。 Workload Security APIを使用して、 Workload Security コンソールを使用して実行できるタスクのすべての予約アクティビティ(推奨スキャンの実行、セキュリティアップデートの確認、クラウドアカウントの同期など)を実行できます。利用可能な予約タスクの種類の詳細については、 Schedule Workload Security のタスク を参照してください。
予約タスクを作成した後は、いつでも実行できます。また、作成時にすぐに実行してからすぐに削除することもできます。このように、スケジュールされたタスクを使用すると、 Workload Security をAPIおよびSDKを使用して自動化するための強力で便利なツールにアクセスできます。
関連するクラス
予約タスクを使用する場合は、次のSDKクラスを使用します。
ScheduledTasksApi
: Workload Securityでの予約タスクへのアクセスを提供します。スケジュールされたタスクを作成、記述、変更、削除、検索、およびリスト表示できます。ScheduledTask
:予約タスクを表します。ScheduleDetails
:予約タスクの実行スケジュールを定義します。- タスクパラメータクラス:予約タスクが実行するタスクを定義します。(クラスのリストについては、タスクの設定 を参照してください。)
予約タスクの作成
次の一般的な手順を使用して、予約タスクを作成します(詳細については、以下を参照してください)。
ScheduledTask
オブジェクトを作成し、一般的なプロパティを設定します。ScheduleDetails
オブジェクトを作成してタスクの実行スケジュールを定義し、それをScheduledTask
オブジェクトに追加します。- 実行するタスクを定義するタスクパラメータクラスを作成し、それを
ScheduledTask
オブジェクトに追加します。タスクの種類ごとに異なるタスクパラメータクラスを使用できます。[ユーザの同期]および[ソフトウェアアップデートの確認]タスクでは、タスクパラメータクラスは不要です。 ScheduledTasksApi
オブジェクトを使用して、 Workload Securityで予約タスクを作成します。
一般的なプロパティを設定する
ScheduledTask
オブジェクトを作成する場合は、そのオブジェクトを使用して一般的なプロパティを定義します。
- Name
- スケジュールするタスクの種類
- タスクが有効かどうか
- タスクが作成された後に実行されるかどうか
discover_computer_task = api.ScheduledTask()
discover_computer_task.name = "Discover Computers - Daily"
discover_computer_task.type = "discover-computers"
discover_computer_task.run_now = False
一般プロパティを設定したら、スケジュールとタスクを設定して ScheduledTask
オブジェクトに追加します。
スケジュールを作成する
ScheduleDetails
オブジェクトの次のプロパティは、タスクの実行時を制御します。
- 反復タイプ -- (月次、週次、毎日、毎時、またはなし(1回のみ実行))
- 日次、週次、および月次のスケジュールに対する実行の繰り返し。日次および週次の再帰は、間隔(2日ごとなど)で表されます。月次再発の場合は、特定の月を指定します。
- タスクが実行された回数(繰り返し回数)。タスクは、タスクが指定された回数だけ実行されると自動的に削除されます。これは、予約タスクを1回だけ実行する場合に便利です。
- 日次、週次、および月次の反復タイプの開始時刻は、タスクが実行される時刻をミリ秒(エポックタイム)で指定します。 繰り返しが日次および週次の間隔の間隔で表される場合、後続の実行が発生する日または週は、開始時刻から計算されます。たとえば、再帰が2日ごとである場合、開始時刻が月曜日になると、タスクが実行される翌日の水曜日となります。
- 開始時刻の解釈に使用するタイムゾーンです。
ScheduleDetails
オブジェクトは、 Workload Security上の別個のエンティティとして永続化されず、予約タスクの一部として保存されます。 ScheduleDetails
オブジェクトを永続化して、後で他の予約タスクと再利用することはできません。
スケジュールを作成するには、次の一般的な手順を使用します。
ScheduleDetails
オブジェクトを作成して、反復の種類を設定します。- 反復の種類に対応する
ScheduleParameters
オブジェクトを作成し、実行の繰り返しと開始時刻を設定し、ScheduledTask
オブジェクトに追加します。利用可能なScheduleParameters
オブジェクトはDailyScheduleParameters
,HourlyScheduleParameters
,MonthlyScheduleParameters
、およびOnceOnlyScheduleParameters
です。 - 必要に応じて、
ScheduledTask
オブジェクトにタイムゾーンを設定します。
たとえば、毎日のスケジュールの ScheduleDetails
オブジェクトを作成します。
daily_schedule = api.ScheduleDetails()
daily_schedule.recurrence_type = "daily"
DailyScheduleParameters
クラスは、1日のスケジュールに対応します。次の例では、カスタム間隔を使用してスケジュールを設定します。
daily_schedule_parameters = api.DailyScheduleParameters()
daily_schedule_parameters.frequency_type = "custom"
daily_schedule_parameters.custom_interval = custom_interval
daily_schedule_parameters.start_time = start_time
最後に、スケジュールパラメータを ScheduleDetails
オブジェクトに追加します。
daily_schedule.daily_schedule_parameters = daily_schedule_parameters
例:毎日のスケジュール
次の例では、予約タスクで使用する毎日のスケジュールを作成します。
# Create a ScheduleDetails object and set the recurrence type
daily_schedule = api.ScheduleDetails()
daily_schedule.recurrence_type = "daily"
# Specify when the task runs
daily_schedule_parameters = api.DailyScheduleParameters()
# Use a custom frequency type to run the task at daily intervals.
# Every day and only weekdays are other available frequency types.
daily_schedule_parameters.frequency_type = "custom"
daily_schedule_parameters.custom_interval = custom_interval
daily_schedule_parameters.start_time = start_time
# Add the schedule parameters to the schedule details
daily_schedule.daily_schedule_parameters = daily_schedule_parameters
例: 月次スケジュール
次の例では、予約タスクで使用する月次スケジュールを作成します。
# Create a ScheduleDetails object and set the recurrence type
quarterly_schedule = api.ScheduleDetails()
quarterly_schedule.recurrence_type = "monthly"
# Specify when the task runs
monthly_schedule_parameters = api.MonthlyScheduleParameters()
# Set the schedule to run on a specific day of the month.
# Other options are the last day of the month, or a specific weekday of a specific week
monthly_schedule_parameters.frequency_type = "day-of-month"
# Set the day
monthly_schedule_parameters.day_of_month = day
# Set the months to be quarterly
monthly_schedule_parameters.months = ["january", "april", "july", "october"]
# Add the schedule parameters to the schedule details
quarterly_schedule.monthly_schedule_parameters = monthly_schedule_parameters
タスクを設定する
次の各タスクパラメータクラスは、予約タスクの種類に対応します。これらのクラスを使用してタスクを設定します。
CheckForSecurityUpdatesTaskParameters
DiscoverComputersTaskParameters
GenerateReportTaskParameters
RunScriptTaskParameters
ScanForIntegrityChangesTaskParameters
ScanForMalwareTaskParameters
ScanForOpenPortsScanParameters
ScanForRecommendationsScanParameters
SendAlertSummaryScanParameters
SendPolicyTaskParameters
SynchronizeCloudAccountTaskParameters
SynchronizeDirectoryTaskParameters
SynchronizeVCenterTaskParameters
UpdateSuspiciousObjectsListTaskParameters
APIキーに付与された権限によって、使用可能なタスクパラメータクラスが決定されます。たとえば、プライマリテナントがテナントにスクリプトの使用を制限する場合、 RunScriptTaskParameters
クラスはテナントには使用できません。
次の一般的な手順を使用して、タスクオブジェクトを作成および設定します。
-
作成中の予約タスクの種類に対応するクラスからタスクパラメータオブジェクトを作成します。
[ユーザの同期]および[ソフトウェアアップデートの確認]タスクでは、設定は必要ありません。これらのタスクの場合は、タスクパラメータクラスを作成しないでください。
-
タスクパラメータオブジェクトを設定して、タスクの動作を定義します。
- 各クラスは、設定が必要なさまざまなプロパティを定義します。
- いくつかのタスクパラメータクラスでは、
ComputerFilter
オブジェクトで処理対象のコンピュータを特定する必要があります。 - タスクパラメータオブジェクトの種類に応じて、
Recipients
,TagFilter
またはTimeRange
オブジェクトを追加する必要がある場合があります。
たとえば、 ScheduledTask
オブジェクトを作成し、コンピュータが検出されるようにタスクの種類を設定します。
discover_computer_task = api.ScheduledTask()
discover_computer_task.type = "discover-computers"
対応するDiscoverComputerTaskParametersオブジェクトを作成し、プロパティ値を設定します。
task_parameters = api.DiscoverComputersTaskParameters()
task_parameters.discovery_type = "range"
task_parameters.iprange_low = "192.168.60.0"
task_parameters.iprange_high = "192.168.60.255"
task_parameters.scan_discovered_computers = True
次に、DiscoverComputerTaskParametersオブジェクトをScheduledTaskオブジェクトに追加し、 Workload Securityで予約タスクを作成します。
discover_computer_task.discover_computers_task_parameters = task_parameters
scheduled_tasks_api = api.ScheduledTasksApi(api.ApiClient(configuration))
scheduled_task = scheduled_tasks_api.create_scheduled_task(discover_computer_task, api_version)
例: 予約タスクを作成する
次の例では、コンピュータを検出する予約タスクを作成します。
# Create the ScheduledTask object and set the name and type. Do not run now.
discover_computer_task = api.ScheduledTask()
discover_computer_task.name = "Discover Computers - Daily"
discover_computer_task.type = "discover-computers"
discover_computer_task.run_now = False
# Call the createDailyScheduleDetails method to obtain a daily ScheduleDetails object.
# Set the start time to 03:00 DST.
discover_computer_task.schedule_details = create_daily_schedule_details(api, api_exception, 2, 1536030000000);
# Create a DiscoverComputersTaskParameters object.
# The scan applies to a range of IP addresses, and scans discovered computers for open ports.
task_parameters = api.DiscoverComputersTaskParameters()
task_parameters.discovery_type = "range"
task_parameters.iprange_low = "192.168.60.0"
task_parameters.iprange_high = "192.168.60.255"
task_parameters.scan_discovered_computers = True
discover_computer_task.discover_computers_task_parameters = task_parameters
# Create the scheduled task on Workload Security
scheduled_tasks_api = api.ScheduledTasksApi(api.ApiClient(configuration))
scheduled_task = scheduled_tasks_api.create_scheduled_task(discover_computer_task, api_version)
return scheduled_task.id
また、APIリファレンスの 予約タスクの作成 操作を参照してください。
予約タスクの作成、実行、および削除
作成されたタスクをすぐに実行する予約タスクを作成し、予約タスクを削除します。このようにしてスケジュールされたタスクを使用すると、APIを介して多くの Workload Security 機能に簡単にアクセスできます。
ScheduleDetails
オブジェクトの反復カウントが1に設定されている場合、予約タスクは実行後自動的に削除されます。
次の一般的な手順を使用して、予約タスクを作成、実行、および削除します。
-
ScheduledTask
オブジェクトを作成および設定するには- スケジュールされたタスクを今すぐ実行するように設定します。
- 一度実行するタスクを設定して、後続の実行が実行されないようにします。
- 必要に応じてタスクの詳細を作成および設定します。
-
ScheduledTasksApi
オブジェクトを作成し、それを使用して Workload Securityで予約タスクを作成します。 ScheduledTasksApi
オブジェクトを使用して、 Workload Securityで予約タスクを削除します。
次の例では、セキュリティ更新をチェックする予約タスクを作成、実行、および削除します。
# Set the name and task type
check_for_security_updates = api.ScheduledTask()
check_for_security_updates.name = "Check For Security Updates"
check_for_security_updates.type = "check-for-security-updates"
# Run when the scheduled task is created
check_for_security_updates.run_now = True
# Use a once-only recurrence
schedule_details = api.ScheduleDetails()
schedule_details.recurrence_type = 'none'
# Set the recurrence count to 1 so that the task is deleted after running
schedule_details.recurrence_count = 1
schedule_parameters = api.OnceOnlyScheduleParameters()
# The start time is not important because it is deleted after running
schedule_parameters.start_time = 0
schedule_details.once_only_schedule_parameters = schedule_parameters
check_for_security_updates.schedule_details = schedule_details
# Scan all computers
computer_filter = api.ComputerFilter()
computer_filter.type = "all-computers"
# Create the task parameters object and add the computer filter
task_parameters = api.CheckForSecurityUpdatesTaskParameters()
task_parameters.computer_filter = computer_filter
check_for_security_updates.check_for_security_updates_task_parameters = task_parameters
# Create the scheduled task on Workload Security
scheduled_tasks_api = api.ScheduledTasksApi(api.ApiClient(configuration))
scheduled_task = scheduled_tasks_api.create_scheduled_task(check_for_security_updates, api_version)
return scheduled_task.id
また、APIリファレンスの 予約タスクの作成 操作を参照してください。
既存の予約タスクを実行する
既存の予約タスクはいつでも実行できます。たとえば、 Workload Security でネットワーク上のコンピュータを検索する予約タスクが実行され、2日ごとに実行されます。ただし、すぐに予約タスクを実行できるように、今すぐ検索を実行する必要があります。
次の一般的な手順を使用して、予約タスクを実行します。
ScheduledTask
オブジェクトを作成し、runNow
プロパティをtrue
に設定します。他のプロパティは設定しないでください。- 実行する既存の予約タスクのIDを取得します。
ScheduledTasksApi
オブジェクトを作成し、それを使用して作成したScheduledTask
オブジェクトに従って既存の予約タスクを変更します。
runNow
を true
に設定すると、予約タスクは、設定された間隔の現在の時刻に実行されるように設定されます。スケジュールされたタスクを実行した後、開始時刻を元の値にリセットすることもできます。
次の例では、コンピュータの予約検索タスクを実行します。
# Create the ScheduledTask object and set to run now
scheduled_task = api.ScheduledTask()
scheduled_task.run_now = True
# Modify the scheduled task on Workload Security
scheduled_tasks_api = api.ScheduledTasksApi(api.ApiClient(configuration))
scheduled_tasks_api.modify_scheduled_task(scheduled_task_id, scheduled_task, api_version)
また、APIリファレンスの予約タスクの変更も参照してください。