plugin_thold
plugin_thold copied to clipboard
CACTI-Thresholds mails dont sent but test mail success
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Expected behavior A clear and concise description of what you expected to happen.
Screenshots If applicable, add screenshots to help explain your problem.
Plugin (please complete the following information):
- Version: [e.g. 1.2]
- Source: [e.g. cacti.net, package, github]
- Identifer: [e.g. apt/yum package name or github commit ref]
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context
Add any other context about the problem here.
So the problem here is that there is an empty 'to' address for some reason. Check you have set email addresses properly for your thresholds and that there are not two commas if using multiple addresses in a single entry.
The message could be better since there is no message given, will have to take a look at that.
There has been a recent Cacti 1.2.20 commit that should fix this issue with duplicated email addresses causing send failures. I'm guessing this is the problem as it's very similar, but can not say for certain. I would update to Cacti 1.2.20 as soon as it get's released in order to confirm.
I made a little routine to remove all duplicate or misspelled email addresses. This could be used fort he time being. Add the following code before line 5468 in thold_functions.php
/* rotuine to sanitize email-addresses (remove duplicates and empty addresses) */
thold_debug("Before sanitizing : '" . $to_email . "'");
$i_pos = 0; /* position of next comma in string */
$sanitized = ''; /* holds the sanitized emails addresses */
$t_string = ''; /* holds an individual email address */
while (strlen($to_email) > 0) {
$i_pos = strpos($to_email,','); /* get position of next comma */
if ($i_pos > 0) { /* more than one address left */
$t_string = substr($to_email,0,$i_pos); /* extract substring */
/* remove the extracted address from string */
$to_email = substr($to_email,$i_pos+1,strlen($to_email)-$i_pos);
} else { /* last or only email address */
$t_string = $to_email;
$to_email = ''; /* no more data available */
}
/* validate the extracted email address */
if (filter_var($t_string , FILTER_VALIDATE_EMAIL)) { /* there is a vaild email address */
if (is_int(strpos($to_email,$t_string)) == false) { /* single address */
if (strlen($sanitized) > 0) { /* not the first entry */
$sanitized .= ','; /* add a comma for separation */
}
$sanitized .= $t_string; /* add the address to sanitized addresses */
}
}
}
$to_email = $sanitized;
line 5468 thold_debug("Sending email to '" . trim($to_email,', ') . "'");
Good job. Once we get 1.2.20 out the door, thing will be solved.
Someone pointed out that this above routine doesn't work porperly if there are 2 commas without anything in between. I changed the above code into a function which works as well if there multiple commas without any addresses in between. It has to be called before line 5468
$to_email = thold_sanitize_emails($to_email); line 5468 thold_debug("Sending email to '" . trim($to_email,', ') . "'");