Config Info
Name SchedulerMonitor
Version 1.0

About

The goal of this monitor is to be able to schedule the start and ending of monitors execution using Calendars defined in an ini file. This monitor should always be running and, at each refresh, will check whether some monitors should be stopped or started.

Calendar and schedules definition

The calendars time ranges and which monitors should use which calendars are defined in a ini file (by default TS_schedules.ini) according to the following syntax :

;Configuration file for ThinkServer Scheduling ;It contains definitions of calendars and scheduling of monitors according to calendars ;A calendar is defined by a Section Calendar_XXX where XXX is the name of the calendar ;a calendar defines activation timeranges oaccording to the day of the week ;the following examples should be helpful ;it is important that the days start on monday and finish on sunday, therefore, writing Sun-Tue doe not make sense  [Calendar_Day] ;day range :from Monday to Thursday  ;time ranges separated with ; : from 9 to 12 and from 2PM to 5.30 PM (note that the times must be written in 24H format) Mon-Thu=9:00-12:00;14:00-17:30 Fri=9:00-12:00 [Calendar_Night] Tue-Thu=17:30-23:59;00:00-9:00 Mon=17:30-23:59 Fri=00:00-9:00 [Calendar_WeekEnd] Fri=17:30-23:59 ;list of days (separated with ;) Sat;Sun=00:00-23:59 Mon=00:00-9:00 ;The section Scheduling maps monitors to the above-defined calendars ;the syntax is the following : Monitor Name=CalendarName [Scheduling] Ping Monitor 1=Day Ping Monitor 2=Night Ping Monitor 4=Night Ping Monitor 6=Night Ping Monitor 3=WeekEnd Ping Monitor 5=WeekEnd 

 

How to use it

  1. Copy the .py library into the PythonLib folder of ThinkServer
  2. Copy the .ini file into ThinkServer's main folder, or anywhere you think it may be convenient
  3. Import the Scheduler monitor
  4. If the .ini file is not in the ThinkServer folder, update the Additional parameters with the path to that file
  5. Create calendars in the .ini files
  6. assign monitors to the calendars
  7. start the scheduling monitor

Messages sent

This monitor sends messages when monitors are started / stopped or when a scheduled monitor does not exist.

 

Monitor - T04_Scheduler - File TS_schedules.ini

General

Property Value
ClassID GenericPython.1
Description T04_Scheduler - File TS_schedules.ini
GenerateHealthEvent 2
Name T04_Scheduler - File TS_schedules.ini
RedirectHealthEvent 5

 

Script - SetHealth

Additional Parameters

Name Type Value
ScheduleFile String TS_schedules.ini
NbMonitorsStarted Numeric 0
NbMonitorsStopped Numeric 0
NbMonitorsMissing Numeric 0

 

Pre-Group

if VSMScriptFirstEvent: import sys try: from TS_scheduling import load_schedule_from_file except ImportError: raise ImportError("""Could not import module TS_Scheduling. Check that the file TS_Scheduling.py is in the ThinkServer folder""") sys.exit() #reload schedule from file schedule = load_schedule_from_file(ScheduleFile) 

 

Pre-Health Check

active_calendars = list(schedule.list_active_calendars()) inactive_calendars = list(schedule.list_inactive_calendars()) NbMonitorsStarted = 0 NbMonitorsStopped = 0 NbMonitorsMissing = 0 NotChangedMonitors = set() #start monitors that should be started for monitor_name in schedule.list_active_monitors(): #check if monitor exists activity_ID = GetMonitorActivity(monitor_name) #check if monitor is started if activity_ID<0: #monitor doesn't exist SendMessageToSmartConsole (CRITICAL,"Monitor \"%s\" does not exist and was not started" % (monitor_name,),EventID=10311) SendMessageToConfigurator (CRITICAL,"Monitor \"%s\" does not exist and was not started" % (monitor_name,)) NbMonitorsMissing += 1 elif activity_ID == ACTIVITY_RUNNING: NotChangedMonitors.add(monitor_name) else: SendMessageToSmartConsole (MINOR,"Starting monitor \"%s\"" % (monitor_name,),EventID=10313) SendMessageToConfigurator (MINOR,"Starting monitor \"%s\"" % (monitor_name,)) MonitorStart(monitor_name) NbMonitorsStarted +=1 #stop monitor that should be stopped for monitor_name in schedule.list_inactive_monitors(): #check if monitor exists activity_ID = GetMonitorActivity(monitor_name) #check if monitor is started if activity_ID<0: #monitor doesn't exist SendMessageToSmartConsole (CRITICAL,"Monitor \"%s\" does not exist and was not stopped" % (monitor_name,),EventID=10311) SendMessageToConfigurator (CRITICAL,"Monitor \"%s\" does not exist and was not stopped" % (monitor_name,)) NbMonitorsMissing+=1 elif activity_ID == ACTIVITY_STOPPED: NotChangedMonitors.add(monitor_name) else: SendMessageToSmartConsole (WARNING,"Stopping monitor \"%s\"" % (monitor_name,),EventID=10312) SendMessageToConfigurator (WARNING,"Stopping monitor \"%s\"" % (monitor_name,)) MonitorStop(monitor_name) NbMonitorsStopped += 1 #if NotChangedMonitors: # SendMessageToConfigurator (SUCCESS,"These monitors are already in the proper status:\n%s" % (sorted(list(NotChangedMonitors)),)) NotChangedMonitors = sorted(list(NotChangedMonitors)) 

 

Health Rules

Criticity Code
Critical NbMonitorsMissing > 0
Warning NbMonitorsStopped > 0
Minor NbMonitorsStarted > 0
Success True

 

 

Templates

Criticity Code
Critical Some scheduled monitors are missing in the configuration. Check the file &ScheduleFile :

- &NbMonitorsStarted monitors started - &NbMonitorsStopped monitors stopped - &NbMonitorsMissing scheduled monitors do not exist

Currently active calendars : &active_calendars Currently inactive calendars : &inactive_calendars

These monitors are already in the correct status: &NotChangedMonitors

Warning Some monitors were stopped based on the schedules defined in &ScheduleFile :

- &NbMonitorsStarted monitors started - &NbMonitorsStopped monitors stopped - &NbMonitorsMissing scheduled monitors do not exist

Currently active calendars : &active_calendars Currently inactive calendars : &inactive_calendars

These monitors are already in the correct status: &NotChangedMonitors

Minor Some monitors were started based on the schedules defined in &ScheduleFile:

- &NbMonitorsStarted monitors started - &NbMonitorsStopped monitors stopped - &NbMonitorsMissing scheduled monitors do not exist

Currently active calendars : &active_calendars Currently inactive calendars : &inactive_calendars

These monitors are already in the correct status: &NotChangedMonitors

Success No changes in monitor activity based on the schedules defined in &ScheduleFile.

These monitors are already in the correct status: &NotChangedMonitors

 

Sent Variables

ID Variable
VAR02 ScheduleFile
VAR03 NbMonitorsStarted
VAR04 NbMonitorsStopped
VAR05 NbMonitorsMissing
VAR06 T04_SCHEDULING

 

Datasource - Generic Python DataSource

General

Property Value
ClassID GenericPython.1
Description  
ErrorRetryTime 60
IntervalRetries 10
Kind 0
Name Generic Python DataSource
Retries 2
SharingKind 1
Timer 180

 

Implementation

Property Value
BeatRecolectionTime 100

 


Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: October 18, 2018