予約タスクを使用すると、特定のWorkload Securityタスクをスケジュールに従って自動的に実行できます。Workload Security APIを使用して、Workload
Securityコンソールで行うすべての予約タスク関連のアクティビティ (推奨スキャンの実行、セキュリティ更新の確認、クラウドアカウントの同期など) を実行できます。利用可能な予約タスクの種類については、タスクを実行するためのWorkload Securityのスケジュールを参照してください。
予約タスクを作成した後は、いつでも実行できます。また、作成時にすぐに実行してからすぐに削除することもできます。このように、スケジュールされたタスクを使用すると、 Workload
Security をAPIおよびSDKを使用して自動化するための強力で便利なツールにアクセスできます。
関連するクラス
予約タスクを使用する場合は、次のSDKクラスを使用します。
ScheduledTasksApi
: Workload Security上のスケジュールされたタスクにアクセスできます。スケジュールされたタスクの作成、説明、変更、削除、検索、および一覧表示が可能です予約タスク
: 予約タスクを表しますScheduleDetails
: 予約タスクを実行するスケジュールを定義します- タスクパラメータークラス: 予約タスクが実行するタスクを定義します。クラスの一覧については、タスクの構成を参照してください。
予約タスクの作成
予約タスクを作成するには、次の一般的な手順を実行します。
ScheduledTask
オブジェクトを作成し、一般プロパティを構成します。- タスクが実行されるスケジュールを定義するために
ScheduleDetails
オブジェクトを作成し、それをScheduledTask
オブジェクトに追加します。 - タスクパラメータクラスを作成して実行するタスクを定義し、
ScheduledTask
オブジェクトに追加します。タスクの種類ごとに異なるタスクパラメータクラスが用意されています。なお、ユーザの同期とソフトウェア更新の確認タスクにはタスクパラメータクラスは必要ありません。 ScheduledTasksApi
オブジェクトを使用して、Workload Securityで予約タスクを作成します。
一般的なプロパティを設定する
ScheduledTask
オブジェクトを作成する際に、一般プロパティを定義するために使用します。- 名前
- スケジュールするタスクの種類
- タスクが有効かどうか
- 作成後にタスクが実行されるかどうか
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回だけ実行する場合に便利です。
- 毎日、毎週、および毎月の繰り返しタイプの開始時刻によって、タスクが実行される時刻がミリ秒単位で決まります (エポックタイム)。日次および週次のスケジュールで繰り返しが間隔で表される場合、後続の実行が実行される日または週は開始時刻から計算されます。たとえば、繰り返しが隔日である場合、開始時刻が月曜日の場合は、タスクの次の実行日が水曜日であることを意味します。
- 開始時刻の解釈に使用するタイムゾーンです。
ScheduleDetails
オブジェクトはWorkload Security上で別個のエンティティとして保存されるのではなく、予約タスクの一部として保存されることに注意してください。ScheduleDetails
オブジェクトを他の予約タスクで後で再利用するために保存することはできません。スケジュールを作成するには、次の一般的な手順を使用します。
ScheduleDetails
オブジェクトを作成し、繰り返しタイプを設定します。ScheduleParameters
オブジェクトを作成し、繰り返しタイプに対応させ、実行の繰り返しと開始時間を設定して、ScheduledTask
オブジェクトに追加します。利用可能なScheduleParameters
オブジェクトには、DailyScheduleParameters
、HourlyScheduleParameters
、MonthlyScheduleParameters
、およびOnceOnlyScheduleParameters
があります。- オプションで、
ScheduledTask
オブジェクトのタイムゾーンを設定します。
例えば、毎日のスケジュールのために
ScheduleDetails
オブジェクトを作成します。daily_schedule = api.ScheduleDetails() daily_schedule.recurrence_type = "daily"
DailyScheduleParameters
クラスは毎日のスケジュールに対応します。この例では、カスタム間隔を使用してスケジュールを設定します: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
推奨事項のスキャンパラメータをスキャン
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
オブジェクトを予約タスク
オブジェクトに追加し、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レファレンスのスケジュールされたタスクの変更操作も参照してください。