File: graphs.php

package info (click to toggle)
cacti 1.2.30%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 67,176 kB
  • sloc: php: 123,193; javascript: 29,825; sql: 2,595; xml: 1,823; sh: 1,228; perl: 194; makefile: 65; python: 51; ruby: 9
file content (110 lines) | stat: -rw-r--r-- 4,291 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
 +-------------------------------------------------------------------------+
 | Copyright (C) 2004-2024 The Cacti Group                                 |
 |                                                                         |
 | This program is free software; you can redistribute it and/or           |
 | modify it under the terms of the GNU General Public License             |
 | as published by the Free Software Foundation; either version 2          |
 | of the License, or (at your option) any later version.                  |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 +-------------------------------------------------------------------------+
 | Cacti: The Complete RRDTool-based Graphing Solution                     |
 +-------------------------------------------------------------------------+
 | This code is designed, written, and maintained by the Cacti Group. See  |
 | about.php and/or the AUTHORS file for specific developer information.   |
 +-------------------------------------------------------------------------+
 | http://www.cacti.net/                                                   |
 +-------------------------------------------------------------------------+
*/

function get_graph_template_details($local_graph_id) {
	global $config;

	$graph_local = db_fetch_row_prepared('SELECT gl.*, gt.name AS template_name, sqg.name AS query_name
		FROM graph_local AS gl
		LEFT JOIN graph_templates AS gt
		ON gl.graph_template_id = gt.id
		LEFT JOIN snmp_query_graph AS sqg
		ON sqg.id = gl.snmp_query_graph_id
		WHERE gl.id = ?',
		array($local_graph_id));

	$aggregate = db_fetch_row_prepared('SELECT agt.id, agt.name
		FROM aggregate_graphs AS ag
		LEFT JOIN aggregate_graph_templates AS agt
		ON ag.aggregate_template_id=agt.id
		WHERE local_graph_id = ?',
		array($local_graph_id));

	if (!empty($aggregate)) {
		$url = $config['url_path'] . 'aggregate_graphs.php?action=edit&id=';

		if (!empty($aggregate['id'])) {
			return array(
				'id'                => $local_graph_id,
				'name'              => $aggregate['name'],
				'graph_description' => __('Aggregated Device'),
				'url'               => $url . $local_graph_id,
				'source'            => GRAPH_SOURCE_AGGREGATE,
			);
		} else {
			return array(
				'id'                => $local_graph_id,
				'name'              => __('Not Templated'),
				'graph_description' => __('Not Applicable'),
				'url'               => $url . $local_graph_id,
				'source'            => GRAPH_SOURCE_AGGREGATE,
			);
		}
	} elseif ($graph_local['graph_template_id'] == 0) {
		return array(
			'id'     => $local_graph_id,
			'name'   => __('Not Templated'),
			'url'    => '',
			'source' => GRAPH_SOURCE_PLAIN,
		);
	} elseif ($graph_local['snmp_query_id'] > 0 && $graph_local['snmp_query_graph_id'] > 0) {
		$url = $config['url_path'] . 'data_queries.php' .
			'?action=item_edit' .
			'&id=' . $graph_local['snmp_query_graph_id'] .
			'&snmp_query_id=' . $graph_local['snmp_query_id'];

		return array(
			'id'     => $graph_local['snmp_query_graph_id'],
			'name'   => (!empty($graph_local['query_name']) ? $graph_local['query_name'] : __('Not Found')),
			'url'    => $url,
			'source' => GRAPH_SOURCE_DATA_QUERY
		);
	} elseif ($graph_local['snmp_query_id'] > 0 && $graph_local['snmp_query_graph_id'] == 0) {
		return array(
			'id'     => 0,
			'name'   => __('Damaged Graph'),
			'url'    => '',
			'source' => GRAPH_SOURCE_DATA_QUERY
		);
	} else {
		if (!empty($graph_local['template_name'])) {
			$url = $config['url_path'] . 'graph_templates.php?action=template_edit&id=' . $graph_local['graph_template_id'];

			return array(
				'id'     => $graph_local['graph_template_id'],
				'name'   => $graph_local['template_name'],
				'url'    => $url,
				'source' => GRAPH_SOURCE_TEMPLATE,
			);
		} else {
			return array(
				'id'     => 0,
				'name'   => __('Not Found'),
				'url'    => '',
				'source' => GRAPH_SOURCE_TEMPLATE,
			);
		}
	}
}