Mixins

This module contains mixins to extended naghelp with some additional features

GaugeMixin

class naghelp.GaugeMixin

Gauge response helper Mixin

This mixin helps to build a response when one expect a value (gauge) to not move up,down or to be in range. it has be to be declared in the parent classes of a plugin class, before ActivePlugin class. Methods have to be used into naghelp.ActivePlugin.build_response() method. One must call the super naghelp.ActivePlugin.build_response() at the end

Example:

MyPluginWithGauges(GaugeMixin, ActivePlugin):
    ...
    def build_response(self,data):
        ...
        self.gauge_response_etalon_down('fan',   'Fans',   data.boards.grep('Fan Tray').grepc('OK'), WARNING )
        self.gauge_response_etalon_down('board', 'Boards', data.boards.grep('SB|IB').grepc('Available|Assigned'), WARNING )
        self.gauge_response_etalon_down('power', 'Powers', data.boards.grep('^PS').grepc('OK'), WARNING )
        ...
        super(MyPluginWithGauges,self).build_response(data)
gauge_etalon_clear(id)

Clear the reference value for an “etalon” gauge

By this way, you ask the plugin to learn a new reference value

Parameters:id (str) – The id of the gauge
gauge_etalon_set(id, value)

Force a reference value for an “etalon” gauge

Parameters:
  • id (str) – The id of the gauge
  • value (any) – The value that will be the new reference value
gauge_response_etalon_change(id, label, value, level)

Remember a value, detect if it has changed

At the first call the value is stored in host persistent data. The next times, it adds a CRITICAL or WARNING response if the value has changed. The new value is stored and become the new reference value.

Parameters:
  • id (str) – The id of the gauge : an arbitrary string without space (aka slug). This is used for storing the value in persistent data and for debug purposes.
  • label (str) – The gauge meaning. This will be used to build the response message
  • value (any) – The value to test
  • level (naghelp.ResponseLevel) – WARNING or CRITICAL

Example

>>> class MyPluginWithGauges(GaugeMixin, ActivePlugin):
...     pass
...
>>> p=MyPluginWithGauges()
>>> p.doctest_begin()                    # only for doctest
>>> p.gauge_etalon_clear('tempcursor')   # only for doctest
>>> p.gauge_response_etalon_change('tempcursor','Temperature cursor',20,CRITICAL)
>>> print p.response                                  
OK
==========================[ Additionnal informations ]==========================
Temperature cursor : 20
>>> p.doctest_end()
>>> p=MyPluginWithGauges()
>>> p.doctest_begin()                    # only for doctest
>>> p.gauge_response_etalon_change('tempcursor','Temperature cursor',21,CRITICAL)
>>> print p.response                                  
Temperature cursor : actual value (21) has changed (was 20)
==================================[  STATUS  ]==================================

----( CRITICAL )----------------------------------------------------------------
Temperature cursor : actual value (21) has changed (was 20)

==========================[ Additionnal informations ]==========================
Temperature cursor : 21
>>> p.doctest_end()                      # only for doctest
>>> p=MyPluginWithGauges()
>>> p.doctest_begin()
>>> p.gauge_response_etalon_change('tempcursor','Temperature cursor',21,CRITICAL)
>>> print p.response                                  
OK
==========================[ Additionnal informations ]==========================
Temperature cursor : 21
>>> p.doctest_end()
gauge_response_etalon_change_list(id, label_values, level)

Call gauge_response_etalon_change() for all (label,values) tuple in the list label_values

gauge_response_etalon_down(id, label, value, level)

Remember a value, detect if it has changed by going down

At the first call the value is stored in host persistent data. The next times, it adds a CRITICAL or WARNING response if the value has changed by going down. The new value is stored and become the new reference value.

Parameters:
  • id (str) – The id of the gauge : an arbitrary string without space (aka slug). This is used for storing the value in persistent data and for debug purposes.
  • label (str) – The gauge meaning. This will be used to build the response message
  • value (any) – The value to test
  • level (naghelp.ResponseLevel) – WARNING or CRITICAL

Example

>>> class MyPluginWithGauges(GaugeMixin, ActivePlugin):
...     pass
...
>>> p=MyPluginWithGauges()                   # 1st plugin execution
>>> p.doctest_begin()                        # only for doctest
>>> p.gauge_etalon_clear('tempcursor')       # only for doctest
>>> p.gauge_response_etalon_down('tempcursor','Temperature cursor',20,CRITICAL)
>>> print p.response                                  
OK
==========================[ Additionnal informations ]==========================
Temperature cursor : 20
>>> p.doctest_end()
>>> p=MyPluginWithGauges()                   # 2nd plugin execution
>>> p.doctest_begin()                        # only for doctest
>>> p.gauge_response_etalon_down('tempcursor','Temperature cursor',19,CRITICAL)
>>> print p.response                                  
Temperature cursor : actual value (19) is less than the reference value (20...
... )
==================================[  STATUS  ]==================================

----( CRITICAL )----------------------------------------------------------------
Temperature cursor : actual value (19) is less than the reference value (20)

==========================[ Additionnal informations ]==========================
Temperature cursor : 19
>>> p.doctest_end()                          # only for doctest
>>> p=MyPluginWithGauges()
>>> p.doctest_begin()                        # only for doctest
>>> p.gauge_response_etalon_down('tempcursor','Temperature cursor',19,CRITICAL)
>>> print p.response                                  
OK
==========================[ Additionnal informations ]==========================
Temperature cursor : 19
>>> p.doctest_end()                          # only for doctest
gauge_response_etalon_down_list(id, label_values, level)

Call gauge_response_etalon_down() for all (label,values) tuple in the list label_values

gauge_response_etalon_up(id, label, value, level)

Remember a value, detect if it has changed by going up

At the first call the value is stored in host persistent data. The next times, it adds a CRITICAL or WARNING response if the value has changed by going up. The new value is stored and become the new reference value.

Parameters:
  • id (str) – The id of the gauge : an arbitrary string without space (aka slug). This is used for storing the value in persistent data and for debug purposes.
  • label (str) – The gauge meaning. This will be used to build the response message
  • value (any) – The value to test
  • level (naghelp.ResponseLevel) – WARNING or CRITICAL

Example

>>> class MyPluginWithGauges(GaugeMixin, ActivePlugin):
...     pass
...
>>> p=MyPluginWithGauges()                   # 1st plugin execution
>>> p.doctest_begin()                        # only for doctest
>>> p.gauge_etalon_clear('tempcursor')       # only for doctest
>>> p.gauge_response_etalon_up('tempcursor','Temperature cursor',20,CRITICAL)
>>> print p.response                                  
OK
==========================[ Additionnal informations ]==========================
Temperature cursor : 20
>>> p.doctest_end()
>>> p=MyPluginWithGauges()                   # 2nd plugin execution
>>> p.doctest_begin()                        # only for doctest
>>> p.gauge_response_etalon_up('tempcursor','Temperature cursor',21,CRITICAL)
>>> print p.response                                  
Temperature cursor : actual value (21) is more than the reference value (20...
... )
==================================[  STATUS  ]==================================

----( CRITICAL )----------------------------------------------------------------
Temperature cursor : actual value (21) is more than the reference value (20)

==========================[ Additionnal informations ]==========================
Temperature cursor : 21
>>> p.doctest_end()                          # only for doctest
>>> p=MyPluginWithGauges()
>>> p.doctest_begin()                        # only for doctest
>>> p.gauge_response_etalon_up('tempcursor','Temperature cursor',21,CRITICAL)
>>> print p.response                                  
OK
==========================[ Additionnal informations ]==========================
Temperature cursor : 21
>>> p.doctest_end()                          # only for doctest
gauge_response_etalon_up_list(id, label_values, level)

Call gauge_response_etalon_up() for all (label,values) tuple in the list label_values

gauge_response_threshold(id, label, value, warn_min=None, crit_min=None, warn_max=None, crit_max=None)

Test a value and add a WARNING or CRITICAL response if the value is out of range

It also add gauges value in the response’s additional informations section

Parameters:
  • id (str) – The id of the gauge : an arbitrary string without space (aka slug). This is used for debug purposes.
  • label (str) – The gauge meaning. This will be used to build the response message
  • value (str, int or float) – The value to test. If the value is a string, it will detect the first numeric value.
  • warn_min (int or float) – The lower threshold for WARNING response
  • crit_min (int or float) – The lower threshold for CRITICAL response
  • warn_max (int or float) – The upper threshold for WARNING response
  • crit_max (int or float) – The upper threshold for CRITICAL response

Example

>>> class MyPluginWithGauges(GaugeMixin, ActivePlugin):
...     pass
...
>>> p=MyPluginWithGauges()
>>> p.gauge_response_threshold('test','Test gauge','90',0,10,70,100)
>>> print p.response                         
Test gauge : 90 >= MAX WARNING (70)
==================================[  STATUS  ]==================================

----( WARNING )-----------------------------------------------------------------
Test gauge : 90 >= MAX WARNING (70)

==========================[ Additionnal informations ]==========================
Test gauge : 90
>>> p=MyPluginWithGauges()
>>> p.gauge_response_threshold('test','Test gauge','-10',0,10,70,100)
>>> print p.response                         
Test gauge : -10 <= MIN CRITICAL (10)
==================================[  STATUS  ]==================================

----( CRITICAL )----------------------------------------------------------------
Test gauge : -10 <= MIN CRITICAL (10)

==========================[ Additionnal informations ]==========================
Test gauge : -10
>>> p=MyPluginWithGauges()
>>> p.gauge_response_threshold('test','Test gauge','Temperature=110C',0,10,70,100)
>>> print p.response                         
Test gauge : 110 >= MAX CRITICAL (100)
==================================[  STATUS  ]==================================

----( CRITICAL )----------------------------------------------------------------
Test gauge : 110 >= MAX CRITICAL (100)

==========================[ Additionnal informations ]==========================
Test gauge : Temperature=110C
gauge_response_threshold_list(id, label_values, warn_min=None, crit_min=None, warn_max=None, crit_max=None)

Test a list of values and add a WARNING or CRITICAL response if the value is out of range

It calls gauge_response_threshold() for each (label,value) specified in the label_values list.

Parameters:
  • id (str) – The id of the gauge : an arbitrary string without space (aka slug). This is used for debug purposes.
  • label_values (list) – A list of tuple (label,value) where label is the gauge meaning and value is the value to test.
  • warn_min (int or float) – The lower threshold for WARNING response
  • crit_min (int or float) – The lower threshold for CRITICAL response
  • warn_max (int or float) – The upper threshold for WARNING response
  • crit_max (int or float) – The upper threshold for CRITICAL response