Ad Widget

Collapse

Graph on email notification

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • frezende
    Junior Member
    • Mar 2019
    • 2

    #1

    Graph on email notification

    Hi guys,

    I've been trying to include a graph on my notification alert e-mail based on a trigger severity, but without success. I already tried the ad-hoc url graph, but won't accept the {ITEM-ID} macro, only accepts an integer value. Can someone help me?

    Zabbix version: 4.0
  • xibzab
    Junior Member
    • Jul 2020
    • 3

    #2
    Hi there,

    I'm also struggeling with the same "problem". It can't be that hard to put a simple graph with tha latest data (last 6hours/24hours/week...) of the triggered sensor into the notification mail?!!?

    https://www.zabbix.com/documentation...ed_by_location isn't going to help. I also can't manage to find the right macros/parameters.

    Using Zabbix v5

    Pls help
    Last edited by xibzab; 08-07-2020, 10:13.

    Comment

    • csmall
      Member
      • Jun 2020
      • 70

      #3
      I am interesting in having this work as well.

      Comment

      • xibzab
        Junior Member
        • Jul 2020
        • 3

        #4
        so with this here I get my chart: .../chart.php?from=now%2FM&to=now%2FM&itemids[0]={ITEM.ID}&type=0&profileIdx=web.item.graph.filter&profileId x2={ITEM.ID}&width=800&height=200

        Issue with that: You won't see anything because this is a "live chart" and needs authentication.

        Any ideas on how to export this URL to a static image which is attached to the notification mail?

        Comment

        • hoppa
          Junior Member
          • Feb 2021
          • 17

          #5
          Found several topics across the forum where people are asking for such a function for quite a long time already. Also wanted to have this myself and decided to do some fun coding also to get a better knowledge of the internals of Zabbix.

          I've just finished coding a working "proof of concept" PHP Webhook based Media Type called "MailGraph" that picks up the event, finds out if there is a graph associated and sends out an e-mail with the graph.
          The PHP script fetches the objects (item, host, event, graphs) via the API, logs in to Zabbix, grabs the graph and composes a template based e-mail.

          If you're interested I can post the code/instructions on Git after polishing the code a bit more?

          Comment

          • hoppa
            Junior Member
            • Feb 2021
            • 17

            #6
            Example how this looks like (taken from the actual e-mail sent out):

            Click image for larger version

Name:	26-02-2021 14-32-12.png
Views:	5271
Size:	30.6 KB
ID:	419588
            Attached Files

            Comment

            • Waheed
              Junior Member
              • Jan 2021
              • 14

              #7
              hoppa good job can you post code/instructions for mail with graph configuration ?

              Comment

              • hoppa
                Junior Member
                • Feb 2021
                • 17

                #8
                Okay, here we go: https://github.com/moudsen/mailGraph. Note that I'm still working on the code and the manual. Appreciate any feedback (also if it works ... :-)).

                Comment

                • hoppa
                  Junior Member
                  • Feb 2021
                  • 17

                  #9
                  Just to let you know I've release v1.19 which is a version very close to my next milestone of v1.20 where I will leave BETA status. If you an earlier version installed, make sure to replace mailGraph.php and the Javascript code (refer to /javascript) within the Media Type in Zabbix to get the latest and greatest functionality!

                  Enhancements:
                  - Dynamic variables from Zabbix that you can use in the TWIG template (ultimate flexibility in template based information gathering and processing)
                  - Direct to specific graph per Trigger
                  - Different settings per Trigger (width, height, legend, period) thru definition of Tags
                  - Smarter graph locator (finding an associate graph through the trigger functions)
                  - Configurable mail server settings, including support for TLS and SSL and username/password (if required)
                  - Bugfixes and workarounds (i.e. found graph.get issue not returning all associated graphs information requested)

                  One final thing to do before going out of BETA is to have a Responsive template, although the current table based template is already quite useful!
                  If you decide to put v1.19 to a wider audience do keep an eye on the DEBUG settings at the beginning of the code (disable cDebugMail for example).

                  After releasing v1.20 I will focus on getting the graph generator code separated from my code to make it reusable for other webhook/scripts to allow for inclusion in Telegraf, Slack and others and to prepare for the announced API based image call by Zabbix development (and perhaps to give some pointers in what kind of functionality would be nice to have for finding and generating the graph), although one needs to notice that the requested functionality is open sinds 2010 ... :-).

                  Very interested to learn from anyone if MailGraph add value and to identify further enhancements!
                  Last edited by hoppa; 05-03-2021, 14:12.

                  Comment

                  • hoppa
                    Junior Member
                    • Feb 2021
                    • 17

                    #10
                    v1.20 released. Responsive html added and fixed some minor bugs. Leaving BETA mode!

                    Comment

                    • hoppa
                      Junior Member
                      • Feb 2021
                      • 17

                      #11
                      v1.21 released. Optimized graph.get and fixed some minor bugs (mostly log related).

                      Comment

                      • Sebastian
                        Member
                        • Jul 2020
                        • 33

                        #12
                        Hello
                        I had the same problem here.
                        Was able to figure it out.
                        There is needed info in the forum to create alerts like this I believe.

                        Check it out, screenshots of mail alerts attached.

                        Attached Files

                        Comment


                        • hoppa
                          hoppa commented
                          Editing a comment
                          Cool. Do you have a pointer for me where these are advertized?
                      • Sebastian
                        Member
                        • Jul 2020
                        • 33

                        #13
                        Sure,
                        Good start is typing in g ogle string "sending-email-and-wechat-alarm-with-pictures-in-zabbix" , how to add graphs it should be on the first return

                        This runs as custom alertscript,
                        additionnall there is need to create custom HTML alert template.

                        There is actually some work to do, and fit somebody needs.

                        Comment


                        • hoppa
                          hoppa commented
                          Editing a comment
                          Hi Sebastian,

                          We seem to have different starting points for developing a similar solution to enclose pictures in messages. My initiative was triggered from https://support.zabbix.com/browse/ZBXNEXT-5611 where people are waiting for Zabbix developers to come up with a solution (for over 10 years now ...).

                          I've read your work and understand the custom alert script mechanism applied opposite to where I've explicitely chosen to use the Zabbix mechanism to separate the alert cause from the alert follow-up while using the Media Type to bind alerts to message sending services (https://www.zabbix.com/documentation.../media/webhook). You could consider doing the same thing which could turn your code into a standard Media Type as well for easy consumption in Zabbix?
                          My next goal is to separate the Graph get code to become stand-alone to allow other scripts to start using it (look at the ZBXNEXT-5611 where this is asked for Telegraph). My first attempt will be for Slack.

                          Templating is definitely worth looking into. I've used TWIG for this but that's PHP based, not sure if there is a Python variant for it, but bet there is something similar out there doing the same (like https://wiki.python.org/moin/Templating).
                          Basically it's about applying MVC modelling approach: separate data (and config) from model and controller.

                          Best regards, Mark
                      • Sebastian
                        Member
                        • Jul 2020
                        • 33

                        #14
                        That's correct Mark, your way to do it is way more universal and in the end of the day it's always better to do it your way.
                        Anyway having possibility to send graph in mail is improving Zabbix experience significantly. I hope it will be soon available out of the box, Thanks to your work.

                        Comment


                        • hoppa
                          hoppa commented
                          Editing a comment
                          Appreciate your work likewise. It has inspired me to add a (configurable) "multigraph" mode to MailGraph :-). Let's indeed wait/hope for Zabbix to include this out of the box!
                      • hoppa
                        Junior Member
                        • Feb 2021
                        • 17

                        #15
                        v1.22 released. Ability added to have multiple graphs embedded at once at a configurable period of time and with configurable header text that can be configured system wide or per Trigger. Also fixed some minor bugs and added "debug" option (set in either way from config.json or from Zabbix macro).

                        Comment

                        Working...