Having trouble adding graphs to Alert Emails

Im having trouble with the syntax to add graphs to emial notifications, I tried a few that I found on the forum but cant get them to work. I did add the

$config[‘allow_unauth_graphs’] = 1;

To my config file but I just get a broken image link in the emails below is the code I currently have.

> _{foreach %faults}%value.sysDescr<br><br>_
> _<img src="http://servername/graph?width=459&height=213&lazy_w=552&from=end-24h&device=%value.device_id&type=device_bits&legend=yes"><br><br>_
> _{/foreach}_

Ideally what I would want to get is the graph for what is creating the alert ie. Memory, CPU etc. etc. Anyone that has this working that can help me out.

graph.php rather than just graph

Where are you saying in the img src url?

http://servername/graph?

Should be

http://servername/graph.php?

Thank you for the clarification I made the change but I’m still getting the broken image icon. Below is the Full Alert Template Im using and the email it creates.

 %title <br>
Severity: %severity<br>
{if %state == 0}Time elapsed: %elapsed
{/if}Timestamp: %timestamp<br>
Unique-ID: %uid<br>
Rule: {if %name}%name{else}%rule{/if}
{if %faults}<br>Faults:
{foreach %faults}  #%key: %value.string
{/foreach}{/if}Alert sent to: {foreach %contacts}%value <%key> {/foreach}<br>
<br>
{if %transport == mail}<a href="servername/device/device=%hostname/">%hostname</a>{else}%hostname{/if}
<br>
{if %faults}
{foreach %faults}%value.sysDescr<br><br>
<img src="http://servername/graph.php?width=459&height=213&lazy_w=552&from=end-24h&device=%value.device_id&type=device_bits&legend=yes"><br><br>
{/foreach}
{/if}

Right click the image placeholder and get the url, try it and see what output you get

This is odd Im not getting any options to view anything about the image.

image

When Im opening the graph element from the librenms by itself in a new tab this is the url its showing

http://servername/graph.php?id=109&type=mempool_usage&to=1516369800&from=1516283400&height=494.5&width=1228.5


I think I just need to figure out how to make this path use the variables from the Alert Template.

I see where I can set the variable for the id by using id=%value.device_id but Im not sure what the type variable for the alert would be.

Or do I need a different alert template for each type of alert? like one for mempool another for toner and another for storage? I was planning on just using the default alert template.

I added the img_src path as a plain text path into the email and this is the path it returns

http://servername/graph.php?width=459&height=213&lazy_w=552&from=end-24h&device=Array.device_id&type=device_bits&legend=yes

It doesn’t seem to be getting any variables

You don’t need %value.device_id just %device_id, that’s covered in the docs.

Thanks laf the variable does now work I do have another question about the img-src path, if I look at the path on the element for 24hr mem usage I get a path like

src=“graph.php?type=device_mempool&device=52&to=1516647900&from=1516561500&height=494.5&width=1228.5”

If I leave that the way it is I will get a graph but it seems the to and from values change is that a time? Is there a variable that I can use in the alert path for those?

You should be able to use any values that rrdtool uses like -24h for 24 hours ago. -5m for 5 minutes ago, etc.

Is there a variable for type that could be used in the graph pat, that’s based off the alert rule? so a toner alert will look at the toner_usage and mem would look at device_mempool?

Useg the img src path below I get a blank graph

img src="http://servername/graph.php?%device_id&type=device_mempool&height=213&width=459&lazy_w=552&from=end-24h&device&legend=yes"

which returns the path below

"http://servername/graph.php?id=90&type=device_mempool&height=213&width=459&lazy_w=552&from=end-24h&device&legend=yes"

which then creates a blank graph the actual graph element from the server is at path

src="graph.php?type=device_mempool&device=90&to=1516718700&from=1516632300&height=494.5&width=1228.5"

I have no idea why I am having such a hard time with this thanks for you patience laf.

You honestly just need to look at the url that works and break it down. From what you posted above, your template example, what you’re saying is returned and your working example all have different params.

Take each key=value from the working example, work back to that in your template. I can see your issue but you should work it out so you understand for the future.

I understand what your saying and appreciate the help, It looks like the graph path is using the mempool_id field from the mempool table for device= I cant seem to get the variable correct in the email template, I have tried

%mempool_id
%mempool.mempool_id
%value.mempool_id

And none will return the field value. Any suggestions?

%value.mempool_id is correct, needs to be in the loop for %faults.