Email Template, %value.X

Hi

I have read around on this topic but couldn’t find anything on the service part.
Sending alerts in email
https://docs.librenms.org/#Alerting/Templates/

Looking in to Services, and was kindof missing out when I was trying to make a email alert with templates.
when only the possibility was to use “Service_id” and “service_desc” columns from service table.

I have been looking around on LibreNMS repository, and I think I found why only see this.
https://github.com/librenms/librenms/blob/master/includes/alerts.inc.php
line 528

if (!empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1)

What can I do if I want to have access to “service_type” & “service_changed” & “service_message” as well ?
is it simply to add “|| stristr($k, ‘type’) || stristr($k, ‘changed’) || stristr($k, ‘message’)” or would this make trouble ?

Why:
%value.service_type so I can do script like following:
{if %value.service_type == “http”}%HTML%{/if}

%value.service_changed so I can set URI to:
…/graph.php?from=%value.service_changed-6h&to=%value.service_changed…

%value.service_message because it nice to have the message ouput in the mail.

Thanks for your great work :slight_smile:
Apologize in advance, not sure how to do pull request :pensive:

My Version on LibreNMS:

====================================

Component Version
LibreNMS 1.33-409-gacc1ed4
DB Schema 227
PHP 7.0.22-0ubuntu0.16.04.1
MySQL 10.0.31-MariaDB-0ubuntu0.16.04.2
RRDTool 1.5.5
SNMP NET-SNMP 5.7.3

====================================

Check here on to make a PR https://docs.librenms.org/#Developing/Using-Git/

%value.service_type should be available but only in the foreach %fault loop as per the docs.

You should share your template so people can comment on why something might not work.

1 Like

Hi @laf

I did a:
{foreach %faults}
#%key: %value.string
{/foreach}

And have rules like so:

and I was returned:
#1: service_id => 33; service_desc => somedescr”

guess that’s all varibles in array ?

No, you’re just asking for the faults info there not the data from the table.

{foreach %faults}
#%key: %value.string
Service Type: %value.service_type
{/foreach}

Hi @laf

Template:

{if %faults}
{foreach %faults}
TEST			#%key: %value.string										
TEST2 %vaule.service_type
{/foreach}
{/if}

Mail result :

TEST #1: service_id => 33; service_desc => it.Domain.com; TEST2 

Not sure why I don’t see it :confused:

Spelling mistake, take a closer look.

Hi @laf
Sorry I should have seen that

{if %faults}
{foreach %faults}
TEST			#%key: %value.string										
TEST2 %value.service_type
{/foreach}
{/if}

And I got first mail with Service included…
Thanks alot :slight_smile:

Hi @laf

Sorry again :confused:
Can you tell me what im doing wrong here:

{if %faults}
{foreach %faults}
{if %value.service_type == "http"}this is http{/if}
{if %value.service_type == "ssl_cert"}this is ssl{/if}  
{/foreach}
{/if}

okay got it no "

{if %faults}
{foreach %faults}
{if %value.service_type == http}this is http{/if}
{if %value.service_type == ssl_cert}this is ssl{/if}
{/foreach}
{/if}

That was my error