<commit_before>.. _medium/html-and-detailled-notifications:

Shinken email notification plugin
___________________________________

Tired of brut text email notification, want to add more details to them and even make them readable for the common mortals. Then you can use the plugin shipped with Shinken. It can notify as usual in text and also in html in a table with all details needed from the service or host object.

.. image:: /_static/images/shinken-html-notification.png

Here it is the command you can use to have a basic html notification. You have to specify usual shinken macros in option. If not specified then it will try to get them from environment variable if you have set option ``enable_environment_macros`` in ``shinken.cfg`` if you want to used them. It isn't recommanded to use them for large environment. You better use option ``-c``, ``-o`` and ``-s`` or ``-h`` depend on which object you'll notify. Each macros separated by double comma.

Here is commands examples ready to use with it :

::


    define command {
        command_name    host-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n host -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$"" -o ""$HOSTSTATE$,,$HOSTDURATION$"
    }

    define command {
        command_name    service-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n service -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$" -o "$SERVICEDESC$,,$SERVICESTATE$,,$SERVICEOUTPUT$,,$SERVICEDURATION$"
    }

Add an header logo
~~~~~~~~~~~~~~~~~~~~

Let's say that you want to deliver mail to a customer and integrate its logo into, you only have to get a logo, named it ``customer_logo.png`` and paste it into ``/var/lib/shinken/share/images/``.


Detailled Notifications
--------------------------

Detailled notifications is a way to customize and add useful informations in email notification send to your contacts. To do so, use 3 objects macros, services or hosts :

- **_DETAILLEDESC** : Complete and add a more detailled description of service or host.
- **_IMPACT**       : Specify what will be the impact
- **_FIXACTIONS**   : And what is the recommended actions to do when there is an alert about it.

Example 
~~~~~~~~

For example, you can have the below configuration:
our service :

::

  
    define service {
        service_description   Cpu
        use                   20min_long,linux-service
        register              0
        host_name             linux-snmp
        check_command         check_linux_cpu

        _DETAILLEDESC         Detect abnormal CPU usage
        _IMPACT               Slow down applications hosted by the system
        _FIXACTIONS           If recurrent situation then make performance audit
    }

Define our detailled notifications commands adding the detailled informations and used with Shinken plugin so you will have an html email :

::


    ## Notify Host by Email with detailled informations
    # Service have appropriate macros.
    define command {
        command_name    detailled-host-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n host -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$"" -o ""$HOSTSTATE$,,$HOSTDURATION$" -d "$_HOSTDETAILLEDDESC$" -i "$_HOSTIMPACT$"
    }

    ## Notify Service by Email with detailled informations
    # Service have appropriate macros.
    define command {
        command_name    detailled-service-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n service -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$" -o "$SERVICEDESC$,,$SERVICESTATE$,,$SERVICEOUTPUT$,,$SERVICEDURATION$" -d "$_SERVICEDETAILLEDESC$" -i "$_SERVICEIMPACT$" -a "$_SERVICEFIXACTIONS$"
    }

And now define our notification ways:

::


    define notificationway{
       notificationway_name            detailled-email
       service_notification_period     24x7
       host_notification_period        24x7
       service_notification_options    c,w,r
       host_notification_options       d,u,r,f,s
       service_notification_commands   detailled-service-by-email ; send service notifications via email
       host_notification_commands      detailled-host-by-email    ; send host notifications via email
    }  

Then you'll receive a nice html mail giving all your details in a table.<commit_msg>Doc update<commit_after>.. _medium/html-and-detailled-notifications:

Shinken email notification plugin
___________________________________

Tired of brut text email notification, want to add more details to them and even make them readable for the common mortals. Then you can use the plugin shipped with Shinken. It can notify as usual in text and also in html in a table with all details needed from the service or host object.

.. image:: /_static/images/shinken-html-notification.png

Here it is the command you can use to have a basic html notification. You have to specify usual shinken macros in option. If not specified then it will try to get them from environment variable if you have set option ``enable_environment_macros`` in ``shinken.cfg``. It isn't recommended to use them for large environment. You better use option ``-c``, ``-o`` and ``-s`` or ``-h`` depending upon which object you'll notify. Each macros is separated by double comma.

Here is commands examples ready to use:

::


    define command {
        command_name    host-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n host -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$"" -o ""$HOSTSTATE$,,$HOSTDURATION$"
    }

    define command {
        command_name    service-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n service -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$" -o "$SERVICEDESC$,,$SERVICESTATE$,,$SERVICEOUTPUT$,,$SERVICEDURATION$"
    }

Text mail
~~~~~~~~~~~~~~~~~~~~

Despite the nice HTML formatting, you still prefer to use plain old text mail, use the `` -f text`` parameter instead of ``if html``.


Add an header logo
~~~~~~~~~~~~~~~~~~~~

Let's say that you want to deliver mail to a customer and integrate host logo into the mail, you only have to get a logo, name it ``customer_logo.png`` and paste it into ``/var/lib/shinken/share/images/``.

If WebUI2 is installed, then the script will try to find the company logo that can be defined in the WebUI2.  The WebUI2 company logo is PNG file located in ``/var/lib/shinken/share/photos/`` and which name is defined in ``/etc/shinken/modules/webui2.cfg``, property ``company_logo``.


Add a WebUI link
~~~~~~~~~~~~~~~~~~~~

The host or service Web UI link can be included in the mail body. Simply use ``-w (--webui)`` option and you will get a direct link to the host or service page in the Web UI.

The link is built using the current server name and the port defined in the Web UI configuration file.

If WebUI2 is installed, the script will try to find the port number defined in ``/etc/shinken/modules/webui2.cfg``, property ``port``.
If WebUI1 is installed, the script will try to find the port number defined in ``/etc/shinken/modules/webui.cfg``, property ``port``.
If both of them are installed, priority is WebUI2.

If neither WebUI2 nor WebUI are installed on your server, there will be no link in the mail even if this option is used.

If you want to define the root part of the URL, use option ``-u (--url)``. For example: ``-u http://webui.myserver:8080/shinken`` will be used as root part instead of ``http://shinken:7767``.

Detailled Notifications
--------------------------

Detailled notifications is a way to customize and add useful informations in email notification send to your contacts. To do so, use 3 objects macros, services or hosts :

- **_DETAILLEDESC** : Complete and add a more detailled description of service or host.
- **_IMPACT**       : Specify what will be the impact
- **_FIXACTIONS**   : And what is the recommended actions to do when there is an alert about it.

Example
~~~~~~~~

For example, you can have the below configuration:
our service :

::


    define service {
        service_description   Cpu
        use                   20min_long,linux-service
        register              0
        host_name             linux-snmp
        check_command         check_linux_cpu

        _DETAILLEDESC         Detect abnormal CPU usage
        _IMPACT               Slow down applications hosted by the system
        _FIXACTIONS           If recurrent situation then make performance audit
    }

Define our detailled notifications commands adding the detailled informations and used with Shinken plugin so you will have an html email :

::


    ## Notify Host by Email with detailled informations
    # Service have appropriate macros.
    define command {
        command_name    detailled-host-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n host -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$"" -o ""$HOSTSTATE$,,$HOSTDURATION$" -d "$_HOSTDETAILLEDDESC$" -i "$_HOSTIMPACT$"
    }

    ## Notify Service by Email with detailled informations
    # Service have appropriate macros.
    define command {
        command_name    detailled-service-by-email
        command_line    $PLUGINSDIR$/notify_by_email.py -n service -S localhost -r $CONTACTEMAIL$ -f html -c "$NOTIFICATIONTYPE$,,$HOSTNAME$,,$HOSTADDRESS$,,$LONGDATETIME$" -o "$SERVICEDESC$,,$SERVICESTATE$,,$SERVICEOUTPUT$,,$SERVICEDURATION$" -d "$_SERVICEDETAILLEDESC$" -i "$_SERVICEIMPACT$" -a "$_SERVICEFIXACTIONS$"
    }

And now define our notification ways:

::


    define notificationway{
       notificationway_name            detailled-email
       service_notification_period     24x7
       host_notification_period        24x7
       service_notification_options    c,w,r
       host_notification_options       d,u,r,f,s
       service_notification_commands   detailled-service-by-email ; send service notifications via email
       host_notification_commands      detailled-host-by-email    ; send host notifications via email
    }

Then you'll receive a nice html mail giving all your details in a table.
{'fraction_non_alphanumeric': 0.09428352196431997, 'fraction_numerical': 0.0035488202570496835, 'mean_word_length': 3.3391593841032043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5392942', 'n_tokens_mistral': 2950, 'n_tokens_neox': 2892, 'n_words': 1152}