1
1
<?php
2
2
3
3
#------------------------------------------------------------------------------
4
- # Return a version of the string which is safe for display on a web page.
5
- # Potentially dangerous characters are converted to HTML entities.
6
- # Resulting string is not URL-encoded.
4
+ # Functions to make strings compatible
7
5
function clean_string ( $ string ) {
8
6
return htmlentities ( $ string );
9
7
}
10
- #------------------------------------------------------------------------------
11
8
function sanitize ( $ string ) {
12
9
return escapeshellcmd ( clean_string ( rawurldecode ( $ string ) ) ) ;
13
10
}
14
-
15
11
function sanitize_datetime ( $ dt ) {
16
12
if (preg_match ("/^(\d{4}[-\/]\d{2}[-\/]\d{2}|\d{2}[-\/]\d{2}[-\/]\d{4}) \d{1,2}:\d{2}/ " , $ dt )) {
17
13
return date ('H:i_Ymd ' , strtotime ($ dt ));
@@ -20,12 +16,26 @@ function sanitize_datetime ( $dt ) {
20
16
return $ dt ;
21
17
}
22
18
}
19
+
23
20
#------------------------------------------------------------------------------
24
- # If arg is a valid number, return it. Otherwise, return null.
25
- function clean_number ( $ value ) {
26
- return is_numeric ( $ value ) ? $ value : null ;
21
+ # Function to print options for dropdown menus
22
+ function print_dropdown_menus ($ options , $ choice , $ default ) {
23
+ if ( $ default != "" ) {
24
+ $ option_values = " <option value= \"\"> $ default</option> \n" ;
25
+ }
26
+ foreach ($ options as $ option ) {
27
+ if ($ option == $ choice ) {
28
+ $ selected = "selected= \"selected \"" ;
29
+ }
30
+ else {
31
+ $ selected = "" ;
32
+ }
33
+ $ option_values .= " <option value= \"$ option \" $ selected> $ option</option> \n" ;
34
+ }
35
+ return $ option_values ;
27
36
}
28
37
38
+
29
39
#------------------------------------------------------------------------------
30
40
# Function to return graph domainname.
31
41
function get_graph_domainname () {
@@ -46,7 +56,7 @@ function build_graphite_series( $config, $host_cluster = "" ) {
46
56
// Keep track of stacked items
47
57
$ stacked = 0 ;
48
58
$ pie = 0 ;
49
-
59
+
50
60
foreach ( $ config [ 'series ' ] as $ item ) {
51
61
if ( $ item ['type ' ] == "stack " )
52
62
$ stacked ++;
@@ -89,44 +99,68 @@ function build_graphite_series( $config, $host_cluster = "" ) {
89
99
return $ output ;
90
100
}
91
101
92
- function print_graph ($ args , $ metric_report , $ width , $ height , $ from , $ until ) {
102
+ #------------------------------------------------------------------------------
103
+ # Functions for printing graph (cards)
104
+ function print_graph ($ args , $ metric_report , $ graph_size , $ from , $ until ) {
105
+ global $ conf ;
106
+ $ width = $ conf ['graph_sizes ' ][$ graph_size ]['width ' ];
107
+ $ height = $ conf ['graph_sizes ' ][$ graph_size ]['height ' ];
108
+
93
109
$ graph_html = "
94
- <div style = \"display:inline-block \">
95
- <div style = \"display:inline-block; width: $ width ; \">
96
- <a href= \"? $ args&from= $ from&until= $ until \">
97
- <img width= \"$ width \" height= \"$ height \" class= \"lazy \" src= \"img/blank.gif \" data-original= \"" . get_graph_domainname () . "/graph.php? $ args& $ metric_report&from= $ from&until= $ until \" />
98
- </a>
110
+ <div class = \"graph_card \">
111
+ <div class = \"graph_img \">
112
+ <a href= \"? $ args&from= $ from&until= $ until \">
113
+ <img width= \"$ width \" height= \"$ height \" class= \"lazy \" src= \"img/blank.gif \" data-original= \"" . get_graph_domainname () . "/graph.php? $ args& $ metric_report&z= $ graph_size & from=$ from&until= $ until \" />
114
+ </a>
99
115
</div>
100
- " . show_graph_buttons ("$ args& $ metric_report " , $ from , $ until ) . "</div> " ;
116
+ " . show_graph_buttons ("$ args& $ metric_report " , $ from , $ until ) . "</div> " ;
101
117
return $ graph_html ;
102
118
}
103
119
104
- function print_zoom_graph ($ args , $ metric_report , $ width , $ height , $ from , $ until ) {
120
+ function print_zoom_graph ($ args , $ metric_report , $ graph_size , $ from , $ until ) {
121
+ global $ conf ;
122
+ $ width = $ conf ['graph_sizes ' ][$ graph_size ]['width ' ];
123
+ $ height = $ conf ['graph_sizes ' ][$ graph_size ]['height ' ];
124
+
105
125
$ graph_html = "
106
- <div style = \"display:inline-block \">
107
- <div style = \"display:inline-block; width: $ width ; \">
108
- <a href= \"/ graph.php?$ args& $ metric_report&from= $ from&until= $ until&z=xlarge \">
109
- <img width= \"$ width \" height= \"$ height \" class= \"lazy \" src= \"img/blank.gif \" data-original= \"" . get_graph_domainname () . "/graph.php? $ args& $ metric_report&from= $ from&until= $ until \" />
110
- </a>
126
+ <div class = \"graph_card \">
127
+ <div class = \"graph_img \">
128
+ <a href= \"graph.php? $ args& $ metric_report&from= $ from&until= $ until&z=xlarge \">
129
+ <img width= \"$ width \" height= \"$ height \" class= \"lazy \" src= \"img/blank.gif \" data-original= \"" . get_graph_domainname () . "/graph.php? $ args& $ metric_report&z= $ graph_size & from=$ from&until= $ until \" />
130
+ </a>
111
131
</div>
112
- " . show_graph_buttons ("$ args& $ metric_report " , $ from , $ until ) . "</div> " ;
132
+ " . show_graph_buttons ("$ args& $ metric_report " , $ from , $ until ) . "</div> " ;
113
133
return $ graph_html ;
114
134
}
115
135
116
136
function show_graph_buttons ($ args , $ from , $ until ) {
117
- $ button_html = "
118
- <div style= \"display:inline-block; width:16px; \">
119
- <a href= \"/graph_all_periods.php? $ args \">
120
- <img src= \"img/periods_holo_16.png \" width= \"16 \" height= \"16 \" title= \"Show periodic graphs \">
121
- </a>
122
- <a href= \"/graph.php? $ args&from= $ from&until= $ until&z=xlarge \">
123
- <img src= \"img/zoom_holo_16.png \" width= \"16 \" height= \"16 \" title= \"Show XL graph \">
124
- </a>
137
+ $ button_html = "<div class= \"graph_buttons \">
138
+ <a href= \"graph_all_periods.php? $ args \">
139
+ <img src= \"img/periods_holo_16.png \" width= \"16 \" height= \"16 \" title= \"Show periodic graphs \">
140
+ </a>
141
+ <a href= \"graph.php? $ args&from= $ from&until= $ until&z=xlarge \">
142
+ <img src= \"img/zoom_holo_16.png \" width= \"16 \" height= \"16 \" title= \"Show XL graph \">
143
+ </a>
125
144
</div>
126
- " ;
145
+ " ;
127
146
return $ button_html ;
128
147
}
129
148
149
+ function print_period_graph ($ args , $ metric_report , $ timeframe ) {
150
+ global $ conf ;
151
+ $ width = $ conf ['graph_sizes ' ]["large " ]['width ' ];
152
+ $ height = $ conf ['graph_sizes ' ]["large " ]['height ' ];
153
+
154
+ $ graph_html = "
155
+ <div class= \"graph_card \">
156
+ <div class= \"graph_img \">
157
+ <img width= \"$ width \" height= \"$ height \" class= \"lazy \" src= \"img/blank.gif \" data-original= \"" . get_graph_domainname () . "/graph.php? $ args& $ metric_report&z=large&st= $ timeframe+ago \" />
158
+ </div>
159
+ </div>
160
+ " ;
161
+ return $ graph_html ;
162
+ }
163
+
130
164
131
165
#------------------------------------------------------------------------------
132
166
# Finds the max over a set of metric graphs.
@@ -149,6 +183,8 @@ function find_limits($environment, $cluster, $metricname, $start, $end) {
149
183
return $ max ;
150
184
}
151
185
186
+ #------------------------------------------------------------------------------
187
+ # Finds dashboards to specific environment/cluster
152
188
function find_dashboards ($ environment , $ cluster ="" ) {
153
189
global $ conf ;
154
190
@@ -170,6 +206,8 @@ function find_dashboards($environment, $cluster="") {
170
206
return $ graph_reports ;
171
207
}
172
208
209
+ #------------------------------------------------------------------------------
210
+ # Determines of report graphs should be shows in this dashboard
173
211
function show_on_dashboard ($ report_name , $ environment , $ cluster ) {
174
212
global $ conf ;
175
213
@@ -184,6 +222,8 @@ function show_on_dashboard($report_name, $environment, $cluster) {
184
222
return False ;
185
223
}
186
224
225
+ #------------------------------------------------------------------------------
226
+ # Find graphite metrics matching regex
187
227
function find_metrics ($ search_string , $ group_depth =0 ) {
188
228
global $ conf ;
189
229
0 commit comments