GREASE Core

making operations automation automate-able

Configuration Class

class tgt_grease.core.Configuration(ConfigFile=None)

Bases: object

GREASE Configuration Management

This class is responsible for management of configuration of a GREASE Node. Default Configuration will be used if the grease.conf.json document is not found in the root of the GREASE directory. It will ensure all folders/files are in the directory and serve as the access point for configuration data

greaseDir

The root directory of GREASE

Type:str
fs_sep

The filesystem separator for the installed OS

Type:str
greaseConfigFile

Location of the current configuration file

Type:str
FileSystem

Directories of the GREASE filesystem

Type:list
GREASE_CONFIG

Actual config

Type:dict
static DefaultConfig()

Returns the Default GREASE Config

Returns:Default Configuration
Return type:dict
EnsureGreaseFS()

Ensures the GREASE Directory structure is setup

Returns:If the FS is in place then True
Return type:bool
FileSystem = ['etc', 'log']
NodeIdentity = 'Unknown'
static ReloadConfig(ConfigFile=None)

[Re]loads the configuration

Returns:Void Method
Return type:None
fs_sep = '/'
static get(section, key=None, default=None)

Retrieve configuration item

Parameters:
  • section (str) – Configuration Section to read from
  • key (str) – Configuration key to retrieve
  • default (object) – Default value if section/key is not found
greaseConfigFile = '/opt/grease/grease.conf.json'
greaseDir = '/opt/grease/'
set(key, value, section=None)

Set configuration item

Parameters:
  • section (str) – Configuration Section to set
  • key (str) – Configuration key to set
  • value (object) – value to set
Returns:

Sets item only

Return type:

None

Mongo Class

class tgt_grease.core.Mongo(Config=None)

Bases: object

MongoDB Connection Class

_client

The actual PyMongo Connection

Type:pymongo.MongoClient
_config

Configuration Object

Type:Configuration
Client()

get the connection client

Returns:Returns the mongoDB connection client
Return type:pymongo.MongoClient
Close()

Close PyMongo Connection

Returns:Void Method to close connection
Return type:None

Importer Class

class tgt_grease.core.ImportTool(logger)

Bases: object

Import Tooling for getting instances of classes automatically

_log

Logger for the class

Type:Logging
load(className)

Dynamic loading of classes for the system

Parameters:className (str) – Class name to search for
Returns:If an object is found it is returned None: If an object is not found and error occurs None is returned
Return type:object

GreaseContainer

class tgt_grease.core.GreaseContainer(*args, **kwargs)

Bases: object

Inversion of Control Container for objects in GREASE

ensureRegistration()
Returns:
getCollection(collectionName)

Get a collection object from MongoDB

Parameters:collectionName (str) – Collection to get
Returns:Collection instance
Return type:pymongo.collection.Collection
getConfig()

Gets the Configuration Instance

Returns:the configuration instance
Return type:tgt_grease.core.Configuration.Configuration
getLogger()

Get the logging instance

Returns:The logging instance
Return type:Logging
getMongo()

Get the Mongo instance

Returns:Mongo Instance Connection
Return type:Mongo
getNotification()

Get the notifications instance

Returns:The notifications instance
Return type:tgt_grease.core.Notifications

Logging Class

class tgt_grease.core.Logging(Config=None)

Bases: object

Application Logging for GREASE

This is the primary configuration source for GREASE logging. All log information will be passed here to enable centralized log aggregation

_conf

This is an instance of the Config to enable configuring loggers

Type:Configuration
_logger

This is the actual logger for GREASE

Type:logging.Logger
_formatter

This is the log formatter

Type:logging.Formatter
_notifications

Notifications instance

Type:Notifications
foreground

If set will override config and print all log messages

Type:bool
DefaultLogger()

Default Logging Provisioning

Returns:void method to provision class internals
Return type:None
ProvisionLoggers()

Loads Log Handler & Config

Returns:Simple loader, Nothing needed
Return type:None
TriageMessage(message, additional=None, verbose=False, trace=False, notify=False, level=10)

Central message handler

Parameters:
  • message (str) – Message to Log
  • additional (object) – Additional information to log
  • verbose (bool) – To be printed if verbose is enabled
  • trace (bool) – To be printed if trace is enabled
  • notify (bool) – If true will pass through notification system
  • level (int) – Log Level
Returns:

Log Success

Return type:

bool

critical(message, additional=None, verbose=False, trace=False, notify=True)

Critical Messages

Use this method for logging critical statements

Parameters:
  • message (str) – Message to log
  • additional (object) – Additional information to log. Note: object must be able to transform to string
  • verbose (bool) – Print only if verbose mode
  • trace (bool) – Print only if trace mode
  • notify (bool) – Run through the notification management system
Returns:

Message is logged

Return type:

bool

debug(message, additional=None, verbose=False, trace=False, notify=False)

Debug Messages

Use this method for logging debug statements

Parameters:
  • message (str) – Message to log
  • additional (object) – Additional information to log. Note: object must be able to transform to string
  • verbose (bool) – Print only if verbose mode
  • trace (bool) – Print only if trace mode
  • notify (bool) – Run through the notification management system
Returns:

Message is logged

Return type:

bool

error(message, additional=None, verbose=False, trace=False, notify=True)

Error Messages

Use this method for logging error statements

Parameters:
  • message (str) – Message to log
  • additional (object) – Additional information to log. Note: object must be able to transform to string
  • verbose (bool) – Print only if verbose mode
  • trace (bool) – Print only if trace mode
  • notify (bool) – Run through the notification management system
Returns:

Message is logged

Return type:

bool

foreground = False
getConfig()

Getter for Configuration

Returns:The loaded configuration object
Return type:Configuration
getNotification()

Get Notification Class

Returns:The current Notifications instance
Return type:Notifications
info(message, additional=None, verbose=False, trace=False, notify=False)

Info Messages

Use this method for logging info statements

Parameters:
  • message (str) – Message to log
  • additional (object) – Additional information to log. Note: object must be able to transform to string
  • verbose (bool) – Print only if verbose mode
  • trace (bool) – Print only if trace mode
  • notify (bool) – Run through the notification management system
Returns:

Message is logged

Return type:

bool

trace(message, additional=None, verbose=False, trace=True, notify=False)

Trace Messages

Use this method for logging tracing (enhanced debug) statements

Parameters:
  • message (str) – Message to log
  • additional (object) – Additional information to log. Note: object must be able to transform to string
  • verbose (bool) – Print only if verbose mode
  • trace (bool) – Print only if trace mode
  • notify (bool) – Run through the notification management system
Returns:

Message is logged

Return type:

bool

warning(message, additional=None, verbose=False, trace=False, notify=False)

Warning Messages

Use this method for logging warning statements

Parameters:
  • message (str) – Message to log
  • additional (object) – Additional information to log. Note: object must be able to transform to string
  • verbose (bool) – Print only if verbose mode
  • trace (bool) – Print only if trace mode
  • notify (bool) – Run through the notification management system
Returns:

Message is logged

Return type:

bool

Notifier Class

class tgt_grease.core.Notifications(Config=None)

Bases: object

Notification Router for third party resources

This is the class to handle all notifications to third party resources

_conf

Configuration Object

Type:Configuration
hipchat_url

This is the hipchat API url

Type:str
hipchat_token

set this to override the config for the auth token

Type:str
hipchat_room

set this to override the config for the room

Type:str
SendMessage(message, level=10, channel=None)

Send Message to configured channels

This method is the main point of contact with Notifications in GREASE. This will handle routing to all configured channels. Use level to define what level the message is. This can impact whether a message is sent as well as if the message sent will have special attributes (EX: red text). Use channel to route around sending to multiple channels if the message traditionally would go to multiple, instead going only to the selected one.

Note

if you use the channel argument and the channel is not found you will receive False back

Parameters:
  • message (str) – Message to send
  • level (int) – Level of message to be sent
  • channel (str) – Specific channel to notify
Returns:

Success of sending

Return type:

bool

hipchat_room = None
hipchat_token = None
hipchat_url = 'https://api.hipchat.com/v2/room/'
send_hipchat_message(message, level, color=None)

Send a hipchat message

Parameters:
  • message (str) – Message to send to hipchat
  • level (int) – message level
  • color (str) – color of message
Returns:

API response status

Return type:

bool

send_slack_message(message)

Send a slack message to slack channel using webhook url in the configuration

Parameters:message (str) – Message to send to Slack
Returns:API response status
Return type:bool