icinga2 performance data preview via mail notification messages

This forum was archived to /woltlab and is now in read-only mode.
  • Hi.


    Using icinga2 is it possible to send a preview of the Graphite performance data via mail notification messages?
    Naturally in HTML format, like pnp4n_send_service_mail.pl script for Nagios/PNP:
    http://nagios.fm4dd.com/howto/…lexible-notifications.htm


    Please let me know, thanks.
    Bye, Morgan

  • You'll need to ensure that either the image file is embedded into that html mail, or available via public domain (loaded on demand by the recipient's mail client). Since Graphite/Grafana images are rendered with Javascript on the client node, I'm not sure if there is a server-side rendering available providing static image files just for viewing from inside Graphite itself.


    Grafana got a PNG export with 2.x - check this issue: https://github.com/grafana/grafana/issues/565

  • You can probably modify the existing one, but when it comes to html formatting and embedding images, opinion on the layout and design always differ ;-)


    That script is written in Perl, and does a lot of stuff to generate graph images on its own. I guess when you're doing it in your own favorite language (I would go for Python e.g.) you'll feel more familiar. And it would be cool if you could share it then for the community :)

  • This a screnshot of the preview notification plugin for Icinga2 / Graphite / Grafana :)
    When I will finish it I will share it with Icinga2 community ;)


  • Uuu, maybe forking and modifying it! :D
    Now it works only embedding PNG graphs from Grafana2 via API.


    Have you had a look to the Notification scripts of PNP4Nagios ... for Nagios?

  • for some reason the 'fullscreen' parameter breaks the render, so i had to remove it.


    Which grafana version was the script made for?

  • First of all thanks for sharing your notification script with grafana information.


    I was giving it a try on a lab environment before going live, but i have doubts regarding the HOSTURL and PANELURL format.


    On your github commands.conf you use the following custom variables.


    // Custom ENV variables

    HOSTPERFDATA = "$host.perfdata$"

    HOSTURL = "$host.vars.host_url$"

    PANELURL = "$host.vars.panel_url$"


    Then on the notification script you use these variables


    HOSTPERFDATA = os.getenv('HOSTPERFDATA', 'none')

    HOSTURL = os.getenv('HOSTURL', 'none')

    PANELURL = os.getenv('PANELURL', 'none')


    My doubt, and sorry if it is obvious, is what value should HOSTURL and PANELURL have/look like.


    In your examples you indicate how to customize the script, regarding grafanabase, icinga2base, etc. but you do not mention HOSTURL and PANELURL.


    User customization here

    FROM = 'icinga@icinga2.fqdn.here'

    SERVER = 'localhost'

    USERNAME = ''

    PASSWORD = ''

    ICINGA2BASE = 'http://icinga2.fqdn.here/icingaweb2'

    GRAFANABASE = 'http://grafana.fqdn.here:3000'

    GRAFANADASHBOARD = 'yourdashboard'

    GRAFANAVARHOST = 'var-HOST'

    GRAFANATHEME = 'light'

    GRAFANAAPIKEY = 'yourAPIkey'

    WIDTH = '640'

    HEIGHT = '321'

    COLUMN = '144'

    DIFFERENCE = str(int(WIDTH) - int(COLUMN))


    Thanks for your time.

  • Hi pacofer.


    I'm using HOSTURL and PANELURL variables to customize my Icinga2/Graphite/Grafana installation. I specify them into the Icinga2 configuration.


    This is an host example where I use HOSTURL:

    Graphite doesn't use . (dot) symbol, it replaces it with a _ (underscore), so I'm using HOSTURL / host_url for this purpose.

    So this would be an example of the result of notes_url HOST variable:

    http://grafana.mydomain.com:30…ST=srv_ipa01-mydomain_com


    I use PANELURL / panel_url to embed the correct panel ID from my Grafana dashboard into the email message notification. Let's see another example:

    And this is would be the result of the notes_url SERVICE variable:

    http://grafana.mydomain.com:30…omain_com&var-SERVICE=ssh


    Panel ID #4 uses a time value, other IDs use other type values or have specific customizations. I've a default one setted up in the generic-service template, I specify it manually only where needed.


    I hope I was clear to explain the use of these personal variables.
    If you prefer you can exclude from your script, no problem ;)


    Bye, Morgan

  • Thats fantastic, I even would use Your template without grafana. Very well crafted Mail Notification :)


    As I am using hostname and servicename like the influxdb writer example from Icinga2 i changed the following in the python script:

    Code
    1. SERVICEURL = os.getenv('SERVICEURL', SERVICEDESC)
    2. SERVICEURL = SERVICEDESC.replace(" ", "%20") #only quick fix, as it should handle all special chars for URL creating.

    and in the commands:


    Code
    1. HOSTURL = "$host.name$"
    2. SERVICEURL = "$service.name$"


    This way, i don't need to use the custom vars HOSTURL and SERVICEURL anymore.


    Btw. Next time i will not visit monitoring-portal before I'am going to bed. It just to risky to fine some interesting stuff... :sleeping:


  • I have added the changes from dnsmichi to my script. Thanks for the work !


    I still had a big problem on my side: If the paneid is set, but the id does not exists in Grafana you will not get any notifications at all!


    To solve this I added a "try" block here:

    I'am not very phyton, so maybe someone else can make a better execption code. Another problem is, that the Email still links to the image.


    Some other things:

    - need to remove "fullscreen&" from panelpng, as otherwise the image is empty on my server.

    - There is a typo: Service mail says Permormance instead of Performance

    - My Hostcheck is the Icinga cluster check. I needed to add


    Code
    1. elif (len(DATA.split(";")) is 3):
    2.   (VALUE,WARNING,CRITICAL) = DATA.split(";")
    3.   MIN = ''
    4.   MAX = ''

    after:


    Code
    1. if (len(DATA.split(";")) is 5):
    2. (VALUE,WARNING,CRITICAL,MIN,MAX) = DATA.split(";")

    to get it to work proberly.



    Best Regards,

    Rafael


    The post was edited 1 time, last by unic ().