Skip to content

6 MailGraph logic

moudsen edited this page Mar 20, 2021 · 5 revisions

How does MailGraph decide which graph to show?

Let's start with the idea that there is no immediate relationship between a trigger and a graph. This is why the script uses the following technique to find graphs to are associated to the trigger:

  1. The Event API call returns the Event information and holds the "relatedObject" referring to the Trigger that caused the Event. The Value and TriggerId are obtained from this object.
  2. The trigger API call returns a list of "functions". Each functions holds an "item id".
  3. Via the graph API call we can figure out which graphs are associated to the "host id" and to any of the items we've found in the previous step.
  4. Traversing this set of grahps, we are looking for graphs that have the actual "item id" associated. If there is no association found, we can still use any graph as it is still relevant to the trigger, but it will have an indirect relationship.
  5. Most ideally we pick the (first) graph that has the actual "item id" matched. If not, we pick the first graph we've managed to find in our "functions" list.

In reality this may means that there are items (like simple "interface up/down" configured) that have no graphs defined. In this occasion there is no graph attached to the message.

How to point to a specific graph you would like to appear?

If no graph appears or if you wish a specific graph to appear at this point, just add a new graph using that item and next time this graph will show in the message. If you want a specific graph to appear add the tag mailGraph.graph to the trigger pointing at a graph you would like to display for this trigger.

How to add an additional series of graphs that is associated to a Trigger or Host?

Next to adding "item" related graphs, you can also direct MailGraph to add additional graphs for a specific Trigger and/or Host. To make this work you need to setup a "Screen" that has the graphs defined you wish to add to the e-mail message.

When done, pickup the Screen ID (look at the URLs displayed on the "Screens" list) and configure a Tag named mailGraph.screen to the Trigger or Host. You can also define mailGraph.screenPeriod to set the time period that will be displayed for the graphs of this Screen and mailGraph.screenPeriodHeader to set a more readable period header (defaults to mailGraph.screenPeriod).

To ensure the graphs are embedded you need to process the GRAPHS_T (Trigger) and GRAPHS_H (Host) arrays in TWIG (take a look at html.template). Take a look at 5- Templates for additional fieldd that are available if you decide to use these Tags.