saberx.sabercore.triggers package

Submodules

saberx.sabercore.triggers.cpuhandler module

class saberx.sabercore.triggers.cpuhandler.CPUHandler[source]

Bases: object

Class for evaluatingcputrigger params

static check_loadavg(**kwargs)[source]

Method to check loadaverage

This method evaluates the trigger param and descied whether the trigger is fired or not.

Parameters:kwargs (object) – Object containing thresholds and operation
Returns:status of the trigger and error string if any
Return type:bool, string

saberx.sabercore.triggers.cputrigger module

class saberx.sabercore.triggers.cputrigger.CPUTrigger(**kwargs)[source]

Bases: saberx.sabercore.triggers.triggerbase.TriggerBase

Class for creating CPU trigger

fire_trigger()[source]

Method to fire the trigger

This method first sanitises the parameters, calls cpu handler to evaluate the trigger conditions and returns trigger status

Returns:Trigger fired or not
Return type:bool
sanitise()[source]

Method to check validity of the params

Returns:params are proper or not
Return type:bool

saberx.sabercore.triggers.filehandler module

class saberx.sabercore.triggers.filehandler.FileHandler[source]

Bases: object

** Class containing file handling methods **

static is_empty(path)[source]

Method for checking if given file is empty

Parameters:path (string) – path to the file resource
Returns:status, error if any
Return type:bool, string
static is_present(path)[source]

Method for checking if the given file exists

This method checks whether the given path is valid or not.

Parameters:path (string) – path to the file resource
Returns:status, error if any
Return type:bool, string
static read_from_head(path, regex, limit)[source]

Method to read a file from head and see if pattern exists

This method reads a given file and checks if the given pattern exists in the top ‘n’ lines where n is given as ‘limits’.

Parameters:
  • path (string) – path to the file resource
  • regex (string) – string representing the pattern to search for
  • limit (Integer) – Number of lines to query
Returns:

status , error

Return type:

bool, string

static read_from_tail(path, regex, lines)[source]

Method to read a file from end and see if pattern exists

This method reads a given file and checks if the given pattern exists in the last ‘n’ lines where n is given as ‘lines’.

Parameters:
  • path (string) – path to the file resource
  • regex (string) – string representing the pattern to search for
  • limit (Integer) – Number of lines to query
Returns:

status , error

Return type:

bool, string

static search_keyword(**kwargs)[source]

Method to execute the file operation

Method to perform the reuired file operations to execute the trigger

Parameters:kwargs (dict) – Dict containing path, pattern, limit and position to read the file from
Returns:status, error if any
Return type:bool, string

saberx.sabercore.triggers.filetrigger module

class saberx.sabercore.triggers.filetrigger.FileTrigger(**kwargs)[source]

Bases: saberx.sabercore.triggers.triggerbase.TriggerBase

Class for creating file trigger

fire_trigger()[source]

Method to fire the trigger

This method first sanitises the parameters, calls file handler to evaluate the trigger conditions and returns trigger status

Returns:Trigger fired or not
Return type:bool
sanitise()[source]

This method must be implemented by child class

saberx.sabercore.triggers.memoryhandler module

class saberx.sabercore.triggers.memoryhandler.MemoryHandler[source]

Bases: object

Class for handling memory trigger operation

static check_mem(**kwargs)[source]

Method to perform the memory operation

This method accpets the trigger attributes, performs the specified operation and returns the trigger status.

Parameters:kwargs (dict) – Contains all check attributes
Returns:trigger status - fire or not
Return type:bool
static get_mem_type(check)[source]

Method for getting metric type from trigger check

This method accepts the check type and returns the desired method to get the value of the metric specified in type.

Parameters:check (string) – Type of check : virtial | swap
Returns:psutl method to get virtual or swap memory values.
Return type:psutil method

saberx.sabercore.triggers.memorytrigger module

class saberx.sabercore.triggers.memorytrigger.MemoryTrigger(**kwargs)[source]

Bases: saberx.sabercore.triggers.triggerbase.TriggerBase

Class for creating memory trigger

fire_trigger()[source]

Method to fire the trigger

This method first sanitises the parameters, calls memory handler to evaluate the trigger conditions and returns trigger status

Returns:Trigger fired or not
Return type:bool
sanitise()[source]

Method to check validity of the params

Returns:params are proper or not
Return type:bool

saberx.sabercore.triggers.processhandler module

class saberx.sabercore.triggers.processhandler.ProcessHandler[source]

Bases: object

**Class for performing process trigger operation

static check_cmdline(regex)[source]

Method for checking if a process exists by cmdline text

This method checks if there is any process whose cmdline arg matches the given pattern

Parameters:regex (string) – String containing regex
Returns:status, count, error if any
Return type:bool, Integer, String
static check_cmdline_count(regex, count, operator)[source]

Method to get the Number of regex filtered processes by cmd and perform the deired operation

Parameters:
  • regex (string) – Regex to filter processes
  • count (string) – Threshold
  • operation (string) – Desired operation
Returns:

Result, error if any

Return type:

bool, string

static check_name(regex)[source]

Method for checking if a process exists by name

This method checks if there is any process whose name matches the given pattern

Parameters:regex (string) – String containing regex
Returns:status, count, error if any
Return type:bool, Integer, String
static check_name_count(regex, count, operator)[source]

Method to get the Number of regex filtered processes and perform the deired operation

Parameters:
  • regex (string) – Regex to filter processes
  • count (string) – Threshold
  • operation (string) – Desired operation
Returns:

Result, error if any

Return type:

bool, string

static get_cmdline_count(regex)[source]

Method for getting count of process

This method returns the count of processes whose cmdline matches the given regex

Parameters:regex (string) – String containing regex for filtering process cmdline
Returns:status, count, error if any
Return type:bool, Integer, String
static get_name_count(regex)[source]

Method for getting count of process

This method returns the count of processes whose name matches the given regex

Parameters:regex (string) – String containing regex for filtering process names
Returns:status, count, error if any
Return type:bool, Integer, String

saberx.sabercore.triggers.processtrigger module

class saberx.sabercore.triggers.processtrigger.ProcessTrigger(**kwargs)[source]

Bases: saberx.sabercore.triggers.triggerbase.TriggerBase

Class for creating process trigger

fire_trigger()[source]

Method to fire the trigger

This method first sanitises the parameters, calls process handler to evaluate the trigger conditions and returns trigger status

Returns:Trigger fired or not
Return type:bool
sanitise()[source]

Method to check validity of the params

Returns:params are proper or not
Return type:bool

saberx.sabercore.triggers.tcphandler module

class saberx.sabercore.triggers.tcphandler.TCPHandler[source]

Bases: object

Class containing TCP handler methods

static check_connection(**kwargs)[source]

Method to evaluate the TCP trigger

This method evaulates the TCP trigger. Calls the desired methods to check tcp (normal or ssl) to a host.

Parameters:kwargs (dict) – dict containing host, port, ssl, timeout, attempts, threshold, check_type
Returns:status, error if any
Return type:bool, error
static check_tcp(**kwargs)[source]

Check tcp connection to a host

This method tries to open a tcp connection to a host.

Parameters:kwargs (dict) – dict containing host, port and timeout
Returns:Whether the tcp connection could be established or not.
Return type:bool
static check_tcp_ssl(**kwargs)[source]

Check tcp connection with ssl to a host

This method tries to open a ssl tcp connection to a host.

Parameters:kwargs (dict) – dict containing host, port and timeout
Returns:Whether the tcp connection could be established or not.
Return type:bool

saberx.sabercore.triggers.tcptrigger module

class saberx.sabercore.triggers.tcptrigger.TCPTrigger(**kwargs)[source]

Bases: saberx.sabercore.triggers.triggerbase.TriggerBase

Method for initialing memory trigger

fire_trigger()[source]

Method to fire the trigger

This method first sanitises the parameters, calls tcp handler to evaluate the trigger conditions and returns trigger status

Returns:Trigger fired or not
Return type:bool
sanitise()[source]

Method to check validity of the params

Returns:params are proper or not
Return type:bool

saberx.sabercore.triggers.triggerbase module

class saberx.sabercore.triggers.triggerbase.TriggerBase(**kwargs)[source]

Bases: object

eval_negate(triggered, error)[source]
fire_trigger()[source]

This method must be implemented by child class

get_check()[source]
get_type()[source]
is_negate()[source]
sanitise()[source]

This method must be implemented by child class

Module contents