/
1_2_20.php
134 lines (119 loc) · 4.88 KB
/
1_2_20.php
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2021 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 upgrade_to_1_2_20() {
global $config;
include_once($config['base_path'] . '/lib/data_query.php');
// Correct issues with Cacti Data Template input's
db_execute("UPDATE data_input_data
SET t_value = 'on'
WHERE data_input_field_id IN (
SELECT id
FROM data_input_fields
WHERE type_code IN ('host_id', 'output_type', 'index_type', 'index_value')
)
AND data_template_data_id IN (
SELECT id
FROM data_template_data
WHERE data_template_id > 0
)");
$broken_data_sources = db_fetch_assoc("SELECT did.*
FROM data_input_data AS did
WHERE data_input_field_id IN (
SELECT id
FROM data_input_fields
WHERE type_code in ('index_type', 'index_value', 'output_type_id')
)
AND data_template_data_id IN (
SELECT id
FROM data_template_data
WHERE data_template_id > 0
AND local_data_id > 0
) AND value = ''");
if (cacti_sizeof($broken_data_sources)) {
foreach($broken_data_sources as $ds) {
$data_template_data = db_fetch_row_prepared('SELECT *
FROM data_template_data
WHERE id = ?',
array($ds['data_template_data_id']));
$field_data = db_fetch_row_prepared('SELECT *
FROM data_input_fields
WHERE id = ?',
array($ds['data_input_field_id']));
if (cacti_sizeof($data_template_data)) {
$local_data_id = $data_template_data['local_data_id'];
$local_data = db_fetch_row_prepared('SELECT *
FROM data_local
WHERE id = ?',
array($local_data_id));
if (cacti_sizeof($local_data)) {
$local_graph_ids = db_fetch_assoc_prepared('SELECT DISTINCT local_graph_id
FROM data_template_rrd AS dtr
INNER JOIN graph_templates_item AS gti
ON dtr.id = gti.task_item_id
WHERE dtr.local_data_id = ?',
array($local_data_id));
if (cacti_sizeof($local_graph_ids)) {
foreach($local_graph_ids as $id) {
$local_graph = db_fetch_row_prepared('SELECT *
FROM graph_local
WHERE id = ?',
array($id['local_graph_id']));
switch($field_data['type_code']) {
case 'index_type':
$index_type = get_best_data_query_index_type($local_graph['host_id'], $local_graph['snmp_query_id']);
db_execute_prepared('UPDATE data_input_data
SET value = ?
WHERE data_input_field_id = ?
AND data_template_data_id = ?',
array($index_type, $ds['data_input_field_id'], $ds['data_template_data_id']));
break;
case 'index_value':
db_execute_prepared('UPDATE data_input_data
SET value = ?
WHERE data_input_field_id = ?
AND data_template_data_id = ?',
array($local_graph['snmp_index'], $ds['data_input_field_id'], $ds['data_template_data_id']));
break;
case 'output_type_id':
if ($local_graph['snmp_query_graph_id'] == 0) {
$local_graph['snmp_query_graph_id'] = db_fetch_cell_prepared('SELECT id
FROM snmp_query_graph
WHERE graph_template_id = ?
AND snmp_query_id = ?',
array($local_graph['graph_template_id'], $local_graph['snmp_query_id']));
}
db_execute_prepared('UPDATE data_input_data
SET value = ?
WHERE data_input_field_id = ?
AND data_template_data_id = ?',
array($local_graph['snmp_query_graph_id'], $ds['data_input_field_id'], $ds['data_template_data_id']));
break;
}
}
}
}
}
}
}
}