Scheduled Events

InsightCloudSec Bots can spawn jobs that run at specified times with specified arguments. These jobs are called Scheduled Events.

Product name to be replaced

You may observe that some components, screen captures, or examples use our former product name, DivvyCloud. This doesn't affect the configuration or the product's functionality, and we will notify you as we replace these component names.

Reviewing Scheduled Events details in InsightCloudSec

You can review a summary dashboard, Overview, as well as a detailed Event History from the Scheduled Events section of InsightCloudSec. To see this information, navigate to Automation > Scheduled Events. The Overview contains statistics on the number of events, types, and results. The Event History can filter all events by cloud account, Bot, event type, and date range.

Implementation Details

The following sections outline how InsightCloudSec schedules and loads events in the background of the application.

Registration

A job is registered as a scheduled event using the register method of the ScheduledEventManager class, which acts as a class decorator. For example, this is how the StartResourceJob scheduled event is registered in InsightCloudSec:

python
1
from DivvyWorkers.Processors.ScheduledEvents import ScheduledEventManager
2
@ScheduledEventManager.register('divvy.start_resource')
3
class StartResourceJob(MultiResourceScheduledEventJob):
4
...
5

The scheduled event can then be referred to using the unique identifier defined in the register decorator, in this case divvy.start_resource.

Here is an example of how to spawn a scheduled event within a bot action:

python
1
from DivvyBotfactory.scheduling import ScheduledEventTracker
2
3
@registry.action(
4
uid='divvy.action.start_resource_example',
5
bulk_action=True,
6
accepts_complement=True,
7
...
8
)
9
def start_resource_example(bot, settings, matches, non_matches):
10
with ScheduledEventTracker() as context:
11
for resource in matches:
12
context.schedule_bot_event(
13
bot=bot, resource=resource,
14
description='Start a resource.',
15
event_type='divvy.start_resource'
16
schedule_data=schedule.Once(when=datetime.utcnow() + timedelta(hours=12))
17
)
18

Dynamic Loading and Unloading

When developing a plugin that InsightCloudSec dynamically loads and unloads, it is necessary to unload the plugin’s scheduled events. This can be conveniently done using the ScheduledEventRegistryWrapper class, which requires only a minor variation upon the pattern shown above.

An example:

python
1
from DivvyWorkers.Processors.ScheduledEvents import ScheduledEventRegistryWrapper
2
3
# Initialize the registry wrapper
4
events = ScheduledEventRegistryWrapper()
5
6
# Register a scheduled event job
7
events.register('divvy.start_resource')
8
class StartResourceJob(MultiResourceScheduledEventJob):
9
...
10
11
# Handle plugin loading/unloading
12
def load():
13
events.load()
14
def unload():
15
events.unload()
16

A scheduled event registered this way is created and referred to in the same way as before. The only difference is in the specific syntax of how that event is registered.