Change alert emails subject.

Support questions about the Threshold plugin

Moderators: Developers, Moderators

Post Reply
Jacket
Posts: 41
Joined: Tue Sep 30, 2008 11:38 pm
Location: Sofia, Bulgaria

Change alert emails subject.

Post by Jacket »

Hello,
Is there any way to change the subject of the alert emails. I want to have the meaningful name of the thold template, not the data source there. For instance i have this now:
Hostname -PIN2 [pin2] restored to normal threshold with value 25.9494

I have set a meaningful name for this template to Temperature and i want to have this in the subject:

Hostname - Temperature restored to normal threshold with value 25.9494

Is this possible?
[size=92][i]"Ubuntu" - an African word, meaning "Slackware is too hard for me".[/i][/size]
cigamit
Developer
Posts: 3367
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

Its in the works for the next major release, but not currently possible.
crkinard
Posts: 6
Joined: Wed Mar 25, 2009 1:41 pm

Post by crkinard »

Kind of on the same topic: It would be nice to have the option of flagging a e-mail as 'important' as well.
praxis
Posts: 23
Joined: Fri Mar 17, 2006 1:13 pm

Re: Change alert emails subject.

Post by praxis »

I've given up waiting for this to be added as a feature, so I simply edited thold_mail() in thold_functions.php

In my case, we would like threadable alerts per host, so I simply regex out the unique data, i.e. $subject =~ s/threshold.*$/threshold/;

HTH

Edit: took me 30 seconds to figure out I wasnt editing Perl...ended up with this instead of the above example

$subject = preg_replace('/threshold.*$/','threshold',$subject);
$subject = preg_replace('\[.*?\]/','',$subject);

Since I use <SUBJECT> in the message, I can safely trim out unwanted data in the thold_mail function
User avatar
willieb
Cacti User
Posts: 160
Joined: Thu Jan 22, 2009 10:09 am
Location: South GA

Re: Change alert emails subject.

Post by willieb »

I have and love thold 0.4.4-43...

I searched but didn't find anything that would work for me yet. I don't program or understand much code but am looking for a way to change the subject for normal threshold alerts (not down alerts):

Instead of:

[hostname] - [graph template]

something more like:

[graph_title]

Thanks in advance...
-willieb
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Change alert emails subject.

Post by noname »

willieb wrote: Instead of:

[hostname] - [graph template]

something more like:

[graph_title]
As like this post, try to modify 'plugins/thold/thold_functions.php'.
(I'm using thold-0.4.4-41)

At line 561, 592, 631, 649, 694, 622:
$subject = $desc . ($thold_show_datasource ? " [$name]" : '') . ...
to
$subject = $graph_title . ...
And at line about 503:
$hostname = ...
$graph_title = db_fetch_cell('SELECT title_cache FROM graph_templates_graph WHERE local_graph_id = ' . $item['graph_id']);
$rows = ...
Of course this is a provisional way.. At your own risk.
User avatar
willieb
Cacti User
Posts: 160
Joined: Thu Jan 22, 2009 10:09 am
Location: South GA

Re: Change alert emails subject.

Post by willieb »

Once again, thanks noname. It worked perfectly!

Geez I may have to add you to my Christmas list this year lol...

Would it be just as easy to do the same thing for the threshold list itself? Currently my list of thresholds show something like:

Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...

etc...
-willieb
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Change alert emails subject.

Post by noname »

Perhaps default threshold name when created newly can be modified like this..

In 'plugins/thold/thold.php':
'name' => array(
'friendly_name' => 'Threshold Name',
'method' => 'textbox',
'max_length' => 100,
'default' => db_fetch_cell('SELECT title_cache FROM graph_templates_graph WHERE local_graph_id = ' . $graph),
'description' => 'Provide the THold a meaningful name',
'value' => isset($thold_item_data['name']) ? $thold_item_data['name'] : ''
),
For existing thresholds, you can modify its name by hand.
User avatar
willieb
Cacti User
Posts: 160
Joined: Thu Jan 22, 2009 10:09 am
Location: South GA

Re: Change alert emails subject.

Post by willieb »

Thank you.
-willieb
User avatar
willieb
Cacti User
Posts: 160
Joined: Thu Jan 22, 2009 10:09 am
Location: South GA

Re: Change alert emails subject.

Post by willieb »

noname wrote:Perhaps default threshold name when created newly can be modified like this..

In 'plugins/thold/thold.php':
'name' => array(
'friendly_name' => 'Threshold Name',
'method' => 'textbox',
'max_length' => 100,
'default' => db_fetch_cell('SELECT title_cache FROM graph_templates_graph WHERE local_graph_id = ' . $graph),
'description' => 'Provide the THold a meaningful name',
'value' => isset($thold_item_data['name']) ? $thold_item_data['name'] : ''
),
Edit: After more experimentation, your code does work when I create the threshold without a template, but when I use the template I still get

Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
...

for each threshold instead of the graph title.
-willieb
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Change alert emails subject.

Post by noname »

willieb wrote: Edit: After more experimentation, your code does work when I create the threshold without a template, but when I use the template I still get

Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
Arris CMTS - USx Modems [Online] ...
...

for each threshold instead of the graph title.
Okay, then try to modify as follows..

In 'plugins/thold/setup.php':
function thold_data_source_action_execute($action) {
...
if ($graph) {
...
# $insert['name'] = $desc . ' [' . $data_source_name . ']';
$insert['name'] = db_fetch_cell('SELECT title_cache FROM graph_templates_graph WHERE local_graph_id = ' . $graph);
...
and
function thold_graphs_action_execute($action) {
...
if ($graph) {
...
# $insert['name'] = $desc . ' [' . $data_source_name . ']';
$insert['name'] = db_fetch_cell('SELECT title_cache FROM graph_templates_graph WHERE local_graph_id = ' . $graph);
...
I tested this on thold-0.4.4-41. Also 'setup.php' in thold-0.4.4-43 is not different from this version.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: Change alert emails subject.

Post by noname »

P.S.

If you had this error "Threshold(s) Already Exist - No Thresholds Created" when using "Create Threshold from Template",
Image

try commenting out the below line in the above functions.

Code: Select all

$insert['bl_ref_time'] = $template['bl_ref_time'];
(Since 0.4.4-??, that field won't exist in "thold_data" table)
User avatar
willieb
Cacti User
Posts: 160
Joined: Thu Jan 22, 2009 10:09 am
Location: South GA

Re: Change alert emails subject.

Post by willieb »

You know, sometimes I think I need to study php lol...

Ok here's what I did. I kind of went in a different direction. I went back and created a few "traffic" related tholds and realized that it uses the data source name for the thold name, so I went back to the Arris template I was working with and changed the suggestive names in the query to the same as the graph title. When I re-created the graphs it worked great!

With all the problems I've had with 1 minute polling I decided to scrap it and start with a clean install with the default 5 minute polling.

After the fresh Cacti install, I reinstalled thold 0.4.4-43 and everything worked great except for the create thresholds from template, was indeed giving me "Threshold(s) Already Exist - No Thresholds Created"!!

So I just commented out the 2 lines as you suggested in setup.php and everything now works great!

Thanks again noname, I appreciate all your time and effort to help a fellow Cacti user... :-)
-willieb
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests