Beispiel #1
0
/** sig_handler - provides a generic means to catch exceptions to the Cacti log.
 * @arg $signo 	- (int) the signal that was thrown by the interface.
 * @return 		- null */
function sig_handler($signo)
{
    switch ($signo) {
        case SIGTERM:
        case SIGINT:
            reports_log("WARNING: Reports Poller terminated by user", false, "REPORTS TRACE", POLLER_VERBOSITY_LOW);
            exit;
            break;
        default:
            /* ignore all other signals */
    }
}
Beispiel #2
0
/** reports_generate_html  print report to html for online verification
 * @param int $reports_id	- id of report report
 * @param int $output		- type of output
 * @return string			- generated html output
 */
function reports_generate_html($reports_id, $output = REPORTS_OUTPUT_STDOUT)
{
    global $config, $colors;
    global $alignment;
    include_once $config["base_path"] . "/lib/time.php";
    $outstr = "";
    $report = db_fetch_row("SELECT * FROM reports WHERE id={$reports_id}");
    $reports_items = db_fetch_assoc("SELECT * FROM reports_items WHERE report_id=" . $report['id'] . ' ORDER BY sequence');
    $format_data = "";
    $report_tag = false;
    $format_ok = false;
    $time = time();
    # get config option for first-day-of-the-week
    $first_weekdayid = read_graph_config_option("first_weekdayid");
    /* process the format file as applicable */
    if ($report["cformat"] == "on") {
        $format_ok = reports_load_format_file($report["format_file"], $format_data, $report_tag);
    }
    if ($output == REPORTS_OUTPUT_STDOUT) {
        $format_data = str_replace("<html>", "", $format_data);
        $format_data = str_replace("</html>", "", $format_data);
        $format_data = str_replace("<body>", "", $format_data);
        $format_data = str_replace("</body>", "", $format_data);
    }
    if ($format_ok && $report_tag) {
        $include_body = false;
    } else {
        $include_body = true;
    }
    reports_log(__FUNCTION__ . ", items found: " . sizeof($reports_items), false, "REPORTS TRACE", POLLER_VERBOSITY_MEDIUM);
    if (sizeof($reports_items)) {
        if ($output == REPORTS_OUTPUT_EMAIL && $include_body) {
            $outstr .= "<body>\n";
        }
        if ($format_ok) {
            $outstr .= "\t<table class='report_table'>\n";
        } else {
            $outstr .= "\t<table class='report_table' " . ($output == REPORTS_OUTPUT_STDOUT ? "style='background-color:#F9F9F9;'" : "") . " cellspacing='0' cellpadding='0' border='0' align='center' width='100%'>\n";
        }
        $outstr .= "\t\t<tr class='title_row'>\n";
        if ($format_ok) {
            $outstr .= "\t\t\t<td class='title' align='" . $alignment[$report["alignment"]] . "'>\n";
        } else {
            $outstr .= "\t\t\t<td class='title' align='" . $alignment[$report["alignment"]] . "' style='text-align:center; font-size:" . $report["font_size"] . "pt;'>\n";
        }
        $outstr .= "\t\t\t\t" . $report['name'] . "\n";
        $outstr .= "\t\t\t</td>\n";
        $outstr .= "\t\t</tr>\n";
        # this function should be called only at the appropriate targeted time when in batch mode
        # but for preview mode we can't use the targeted time
        # so let's use time()
        $time = time();
        # get config option for first-day-of-the-week
        $first_weekdayid = read_graph_config_option("first_weekdayid");
        /* don't cache previews */
        $_SESSION["custom"] = "true";
        $column = 0;
        foreach ($reports_items as $item) {
            reports_log(__FUNCTION__ . ", item_id: " . $item["id"] . " local_graph_id: " . $item["local_graph_id"], false, "REPORTS TRACE", POLLER_VERBOSITY_MEDIUM);
            if ($item['item_type'] == REPORTS_ITEM_GRAPH) {
                $timespan = array();
                # get start/end time-since-epoch for actual time (now()) and given current-session-timespan
                get_timespan($timespan, $time, $item["timespan"], $first_weekdayid);
                if ($column == 0) {
                    $outstr .= "\t\t<tr class='image_row'>\n";
                    $outstr .= "\t\t\t<td>\n";
                    if ($format_ok) {
                        $outstr .= "\t\t\t\t<table width='100%' class='image_table'>\n";
                    } else {
                        $outstr .= "\t\t\t\t<table cellpadding='0' cellspacing='0' border='0' width='100%'>\n";
                    }
                    $outstr .= "\t\t\t\t\t<tr>\n";
                }
                if ($format_ok) {
                    $outstr .= "\t\t\t\t\t\t<td class='image_column' align='" . $alignment[$item["align"]] . "'>\n";
                } else {
                    $outstr .= "\t\t\t\t\t\t<td style='padding:5px;' align='" . $alignment[$item["align"]] . "'>\n";
                }
                $outstr .= "\t\t\t\t\t\t\t" . reports_graph_image($report, $item, $timespan, $output) . "\n";
                $outstr .= "\t\t\t\t\t\t</td>\n";
                if ($report["graph_columns"] > 1) {
                    $column = ($column + 1) % $report["graph_columns"];
                }
                if ($column == 0) {
                    $outstr .= "\t\t\t\t\t</tr>\n";
                    $outstr .= "\t\t\t\t</table>\n";
                    $outstr .= "\t\t\t</td>\n";
                    $outstr .= "\t\t</tr>\n";
                }
            } elseif ($item['item_type'] == REPORTS_ITEM_TEXT) {
                $outstr .= "\t\t<tr class='text_row'>\n";
                if ($format_ok) {
                    $outstr .= "\t\t\t<td align='" . $alignment[$item["align"]] . "' class='text'>\n";
                } else {
                    $outstr .= "\t\t\t<td align='" . $alignment[$item["align"]] . "' class='text' style='font-size: " . $item["font_size"] . "pt;'>\n";
                }
                $outstr .= "\t\t\t\t" . $item["item_text"] . "\n";
                $outstr .= "\t\t\t</td>\n";
                $outstr .= "\t\t</tr>\n";
                /* start a new section */
                $column = 0;
            } elseif ($item['item_type'] == REPORTS_ITEM_TREE) {
                if (reports_tree_has_graphs($item["tree_id"], 0, $report["user_id"], $item["graph_name_regexp"])) {
                    $outstr .= reports_expand_tree($report, $item, $output, $format_ok);
                }
                if ($item['tree_cascade'] == 'on') {
                    $order_key = db_fetch_cell("SELECT order_key FROM graph_tree_items WHERE graph_tree_id=" . $item['tree_id'] . " AND id=" . $item['branch_id']);
                    $corder_key = rtrim($order_key, '0');
                    $tree_branches = db_fetch_assoc("SELECT id FROM graph_tree_items WHERE graph_tree_id=" . $item['tree_id'] . " AND order_key LIKE '" . $corder_key . "%' AND order_key!='{$order_key}' ORDER BY order_key");
                    if (sizeof($tree_branches)) {
                        foreach ($tree_branches as $branch) {
                            $item["branch_id"] = $branch["id"];
                            if (reports_tree_has_graphs($item["tree_id"], $item["branch_id"], $report["user_id"], $item["graph_name_regexp"])) {
                                $outstr .= reports_expand_tree($report, $item, $output, $format_ok, true);
                            }
                        }
                    }
                }
            } else {
                $outstr .= "<tr><td><br><hr><br></td></tr>";
            }
        }
        $outstr .= "\t</table>\n";
        if ($output == REPORTS_OUTPUT_EMAIL && $include_body) {
            $outstr .= "</body>";
        }
    }
    if ($format_ok) {
        if ($report_tag) {
            return str_replace("<REPORT>", $outstr, $format_data);
        } else {
            return $format_data . "\n" . $outstr;
        }
    } else {
        return $outstr;
    }
}
Beispiel #3
0
function reports_send($id)
{
    global $config;
    /* ================= input validation ================= */
    input_validate_input_number($id);
    /* ==================================================== */
    include_once $config['base_path'] . '/lib/reports.php';
    $report = db_fetch_row('SELECT * FROM reports WHERE id=' . $id);
    if (!sizeof($report)) {
        /* set error condition */
    } elseif ($report['user_id'] == $_SESSION['sess_user_id']) {
        reports_log(__FUNCTION__ . ', send now, report_id: ' . $id, false, 'REPORTS TRACE', POLLER_VERBOSITY_MEDIUM);
        /* use report name as default EMail title */
        if (!strlen($report['subject'])) {
            $report['subject'] = $report['name'];
        }
        if (!strlen($report['email'])) {
            $_SESSION['reports_error'] = "Unable to send Report '" . $report['name'] . "'.  Please set destination e-mail addresses";
            if (!isset($_POST['selected_items'])) {
                raise_message('reports_error');
            }
        } elseif (!strlen($report['subject'])) {
            $_SESSION['reports_error'] = "Unable to send Report '" . $report['name'] . "'.  Please set an e-mail subject";
            if (!isset($_POST['selected_items'])) {
                raise_message('reports_error');
            }
        } elseif (!strlen($report['from_name'])) {
            $_SESSION['reports_error'] = "Unable to send Report '" . $report['name'] . "'.  Please set an e-mail From Name";
            if (!isset($_POST['selected_items'])) {
                raise_message('reports_error');
            }
        } elseif (!strlen($report['from_email'])) {
            $_SESSION['reports_error'] = "Unable to send Report '" . $report['name'] . "'.  Please set an e-mail from address";
            if (!isset($_POST['selected_items'])) {
                raise_message('reports_error');
            }
        } else {
            generate_report($report, true);
        }
    }
}