Skip to content

Commit

Permalink
feature: Allow Reports to be send to a Notification List
Browse files Browse the repository at this point in the history
* This requires thold to first be installed.
  • Loading branch information
TheWitness committed Jan 2, 2025
1 parent f09d5b2 commit a791a08
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ Cacti CHANGELOG
-feature: Add parsedown to vendor library for plugin CHANGELOG and README viewing support
-feature: Add year display to get_daysfromtime function
-feature: Add class and version columns to Graph Template to support Streams feature
-feature: Allow Reports to be sent to a Notification List if thold is installed

1.2.29
-issue#5843: Issue with temporary tables with use of microtime
Expand Down
1 change: 1 addition & 0 deletions cacti.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2672,6 +2672,7 @@ CREATE TABLE `reports` (
`from_email` text NOT NULL,
`email` text NOT NULL,
`bcc` text NOT NULL,
`notify_list` int(10) unsigned NOT NULL default '0',
`attachment_type` smallint(2) unsigned NOT NULL default '1',
`graph_height` smallint(2) unsigned NOT NULL default '0',
`graph_width` smallint(2) unsigned NOT NULL default '0',
Expand Down
4 changes: 4 additions & 0 deletions install/upgrades/1_3_0.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ function upgrade_to_1_3_0() {
db_install_execute("ALTER TABLE automation_networks ADD COLUMN ignore_ips varchar(1024) NOT NULL DEFAULT '' AFTER subnet_range");
}

if (!db_column_exists('reports', 'nofity_list')) {
db_install_execute("ALTER TABLE reports ADD COLUMN notify_list int(10) unsigned NOT NULL DEFAULT '0' AFTER bcc");
}

if (!db_column_exists('poller_output_boost', 'last_updated')) {
db_install_execute('ALTER TABLE poller_output_boost
ADD COLUMN last_updated timestamp NOT NULL default CURRENT_TIMESTAMP,
Expand Down
19 changes: 16 additions & 3 deletions lib/html_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@
'max_length' => 255,
'value' => '|arg1:from_email|'
),
'notify_alert' => array(
'friendly_name' => __('Notification List', 'thold'),
'method' => 'drop_sql',
'description' => __('You may select a Notification List to receive this Report.'),
'value' => '|arg1:notify_list|',
'none_value' => __('None', 'thold'),
'sql' => 'SELECT id, name FROM plugin_notification_lists ORDER BY name'
),
'email' => array(
'friendly_name' => __('To Email Address(es)'),
'method' => 'textarea',
Expand Down Expand Up @@ -193,6 +201,10 @@
),
);

if (!api_plugin_installed('thold')) {
unset($fields_reports_edit['notify_alert']);
}

/**
* Updates the sequence of report items based on the provided order.
*
Expand Down Expand Up @@ -284,9 +296,10 @@ function reports_form_save() {
$save['subject'] = $save['name'];
}

$save['from_name'] = $post['from_name'];
$save['from_email'] = $post['from_email'];
$save['bcc'] = $post['bcc'];
$save['from_name'] = $post['from_name'];
$save['from_email'] = $post['from_email'];
$save['bcc'] = $post['bcc'];
$save['notify_list'] = (isset($post['notify_list']) ? $post['notify_list']:'');

$atype = $post['attachment_type'];

Expand Down
39 changes: 39 additions & 0 deletions lib/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,19 @@ function generate_report($report, $force = false) {
$report['bcc'] = '';
}

if (api_plugin_installed('thold') && $report['notify_list'] > 0) {
$nl_to_emails = get_notification_emails($report['notify_list'], 'to');
$nl_bcc_emails = get_notification_emails($report['notify_list'], 'bcc');

if ($nl_to_emails != '') {
$report['email'] .= ($report['email'] != '' ? ', ':'') . $nl_to_emails;
}

if ($nl_bcc_emails != '') {
$report['bcc'] .= ($report['bcc'] != '' ? ', ':'') . $nl_bcc_emails;
}
}

$v = CACTI_VERSION;

$headers['User-Agent'] = 'Cacti-Reports-v' . $v;
Expand Down Expand Up @@ -2243,3 +2256,29 @@ function reports_run($id) {
db_execute_prepared('DELETE FROM reports_queued WHERE id = ?', array($id));
}

function get_notification_emails($id = '', $recipient = 'to') {
if ($id == '' || $id === null) {
return '';
}

if (!thold_notification_list_enabled($id)) {
return '';
}

if (!empty($id)) {
if ($recipient == 'to') {
return trim(db_fetch_cell_prepared('SELECT emails
FROM plugin_notification_lists
WHERE id = ?',
array($id)));
} else {
return trim(db_fetch_cell_prepared('SELECT bcc_emails
FROM plugin_notification_lists
WHERE id = ?',
array($id)));
}
} else {
return '';
}
}

0 comments on commit a791a08

Please sign in to comment.