Skip to content

Commit

Permalink
Error handling if nems-mailtest run as non-root
Browse files Browse the repository at this point in the history
  • Loading branch information
NEMS Linux committed Apr 12, 2019
1 parent aa8a40b commit 66a8266
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion data/1.5/nagios/plugins/nems_sendmail_host
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,10 @@ if(!$mail->send()) {
echo 'Message could not be sent.' . PHP_EOL;
echo 'Mailer Error: ' . $mail->ErrorInfo . PHP_EOL;
$error = '[' . strtotime('now') . '] NEMS EMAILER: ' . $mail->ErrorInfo . PHP_EOL;
file_put_contents('/var/log/nagios/nagios.log',$error,FILE_APPEND);
if (!file_put_contents('/var/log/nagios/nagios.log',$error,FILE_APPEND)) {
echo 'Could not save log as you are not running as a privileged user.' . PHP_EOL . 'Next time use sudo if this matters to you.';
echo PHP_EOL . $error . PHP_EOL;
}
} else {
echo 'Message has been sent' . PHP_EOL;
}
Expand Down
5 changes: 4 additions & 1 deletion data/1.5/nagios/plugins/nems_sendmail_service
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,10 @@ if(!$mail->send()) {
echo 'Message could not be sent.' . PHP_EOL;
echo 'Mailer Error: ' . $mail->ErrorInfo . PHP_EOL;
$error = '[' . strtotime('now') . '] NEMS EMAILER: ' . $mail->ErrorInfo . PHP_EOL;
file_put_contents('/var/log/nagios/nagios.log',$error,FILE_APPEND);
if (!file_put_contents('/var/log/nagios/nagios.log',$error,FILE_APPEND)) {
echo 'Could not save log as you are not running as a privileged user.' . PHP_EOL . 'Next time use sudo if this matters to you.';
echo PHP_EOL . $error . PHP_EOL;
}
} else {
echo 'Message has been sent' . PHP_EOL;
}
Expand Down

0 comments on commit 66a8266

Please sign in to comment.