-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathchooser.php
303 lines (284 loc) · 11.6 KB
/
chooser.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
///////////
//
// PHP DYNAMIC DROP-DOWN BOX FOR ZABBIX PDF GENERATION
// THE IDEA BEHIND THIS IS TO CREATE A VERSION INDEPENDENT
// ADDON THAT CAN BE ADDED THROUGH SCREENS TO PREVENT BREAKAGE
//
///////////
//
// v0.1 - 1/14/12 - (c) Travis Mathis - [email protected]
// Change Log: Added Form Selection, Data Gathering, Report Generation w/ basic time period selection
// pdfform.php(selection) / generatereport.php(report building) / pdf.php(report)i
// v0.2 - 2/7/12
// Change Log: Removed mysql specific calls and replaced with API calls. Moved config to central file
// v0.5 - 2014/09/05 - Ronny Pettersen <pettersen.ronny @ gmail.com>
// Rewritten a lot based on original from Travis Mathis. Allows reporting on group.
// Uses Jquery (javascript) for many of the functions on the index page.
//
///////////
include("config.inc.php");
if ( $user_login == 1 ) {
session_start();
//print_r($_SESSION);
$z_user=$_SESSION['username'];
$z_pass=$_SESSION['password'];
if ( $z_user == "" ) {
header("Location: index.php");
}
$z_login_data = "name=" .$z_user ."&password=" .$z_pass ."&autologin=1&enter=Sign+in";
}
global $z_user, $z_pass, $z_login_data;
require_once("inc/ZabbixAPI.class.php");
include("inc/index.functions.php");
header( 'Content-type: text/html; charset=utf-8' );
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<title>Zabbix Dynamic PDF Report</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/zabbix/favicon.ico" />
<link rel="stylesheet" type="text/css" href="css/zabbix.default.css" />
<link rel="stylesheet" type="text/css" href="css/zabbix.color.css" />
<link rel="stylesheet" type="text/css" href="css/zabbix.report.css" />
<link rel="stylesheet" type="text/css" href="js/jquery.datetimepicker.css"/ >
<link rel="stylesheet" type="text/css" href="css/tablesorter.css"/ >
<link rel="stylesheet" type="text/css" href="css/select2.css"/ >
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="js/select2.min.js"></script>
<script>
$(function(){
$('#ReportHost').click(function(){
$('#s_ReportHost').prop('disabled',false);
$('#s_ReportHostGroup').prop('disabled',true);
$('#s_ReportHost').prop('required',true);
$('#s_ReportHostGroup').prop('required',false);
$('#p_ReportHostGroup').hide('fast');
$('#p_ReportHost').show('slow');
});
$('#ReportHostGroup').click(function(){
$('#s_ReportHostGroup').prop('disabled',false);
$('#s_ReportHost').prop('disabled',true);
$('#s_ReportHostGroup').prop('required',true);
$('#s_ReportHost').prop('required',false);
$('#p_ReportHost').hide('fast');
$('#p_ReportHostGroup').show('slow');
});
$('#RangeLast').click(function(){
$('#s_RangeLast').prop('disabled',false);
$('#datepicker_start').prop('disabled',true);
$('#timepicker_start').prop('disabled',true);
$('#datepicker_end').prop('disabled',true);
$('#timepicker_end').prop('disabled',true);
$('#datepicker_start').prop('required',false);
$('#p_RangeCustom').hide('fast');
$('#p_RangeLast').show('slow');
});
$('#RangeCustom').click(function(){
$('#datepicker_start').prop('disabled',false);
$('#timepicker_start').prop('disabled',false);
$('#datepicker_end').prop('disabled',false);
$('#timepicker_end').prop('disabled',false);
$('#datepicker_start').prop('required',true);
$('#s_RangeLast').prop('disabled',true);
$('#s_RangeLast').prop('required',false);
$('#p_RangeCustom').show('slow');
$('#p_RangeLast').hide('fast');
});
$('#h_OldReports').click(function(){
$(".d_OldReports").toggleClass('table-hidden');
});
});
$(document).ready(function() {
$('#s_ReportHostGroup').prop('disabled',true);
$('#datepicker_start').prop('disabled',true);
$('#timepicker_start').prop('disabled',true);
$('#datepicker_end').prop('disabled',true);
$('#timepicker_end').prop('disabled',true);
$('#p_ReportHostGroup').hide('fast');
$('#p_RangeCustom').hide('fast');
$('#OldReports').tablesorter();
$("#s_ReportHost").select2({width: "copy"});
$("#s_ReportHostGroup").select2({width: "copy"});
$("#s_RangeLast").select2();
});
</script>
</head>
<body class="originalblue">
<div id="message-global-wrap"><div id="message-global"></div></div>
<table class="maxwidth page_header" cellspacing="0" cellpadding="5"><tr><td class="page_header_l"><a class="image" href="http://www.zabbix.com/" target="_blank"><div class="zabbix_logo"> </div></a></td><td class="maxwidth page_header_r"> </td></tr></table>
<br/><br/>
<center><h1>Generate PDF Report</h1></center>
<br/>
<?php
// ERROR REPORTING
error_reporting(E_ALL);
set_time_limit(60);
// ZabbixAPI Connection
if ($zabbix_version < 5.0 ) {
ZabbixAPI::debugEnabled(TRUE);
}
ZabbixAPI::login($z_server,$z_user,$z_pass)
or die('Unable to login: '.print_r(ZabbixAPI::getLastError(),true));
//fetch graph data host
$hosts = ZabbixAPI::fetch_array('host','get',array('output'=>array('hostid','name'),'sortfield'=>'host','with_graphs'=>'1','sortfield'=>'name'))
or die('Unable to get hosts: '.print_r(ZabbixAPI::getLastError(),true));
if ( $zabbix_version >= 6.2 ) {
$host_groups = ZabbixAPI::fetch_array('hostgroup', 'get', array( 'output' => array('groupid', 'name'), 'sortfield' => 'name'))
or die('Unable to get host groups: ' . print_r(ZabbixAPI::getLastError(), true));
// Now, iterate over these groups to filter them according to specific criteria.
$filtered_host_groups = [];
foreach ($host_groups as $group) {
// Make an API call to fetch hosts by group that have graphs. Adjust this part according to your implementation.
$hosts = ZabbixAPI::fetch_array('host', 'get', array(
'output' => 'extend',
'groupids' => $group['groupid'],
'with_graphs' => '1' // Assuming this filter can be applied here. Adjust as needed.
));
// If hosts with graphs were found in the group, then include the group in the filtered list.
if (!empty(array_filter($hosts))) {
// print_r($hosts);
$filtered_host_groups[] = $group;
}
}
// Reassign the filtered groups back to $host_groups so the rest of the code is unaffected.
$host_groups = $filtered_host_groups;
# print_r($host_groups);
} else {
$host_groups = ZabbixAPI::fetch_array('hostgroup','get', array('output'=>array('groupid','name'),'real_hosts'=>'1','with_graphs'=>'1','sortfield'=>'name') )
or die('Unable to get hosts: '.print_r(ZabbixAPI::getLastError(),true));
}
ZabbixAPI::logout($z_server,$z_user,$z_pass)
or die('Unable to logout: '.print_r(ZabbixAPI::getLastError(),true));
//var_dump($hosts);
//var_dump($host_group);
// Form dropdown boxes from Zabbix API Data
?>
<center>
<form class="cmxform" id="ReportForm" name="ReportForm" action='createpdf.php' method='GET'>
<table border="1" rules="NONE" frame="BOX" width="600" cellpadding="10">
<tr><td valign="middle" align="left" width="115">
<label for="ReportType"><b>Report type</b></label>
</td><td valign="center" align="left" height="30">
<p>
<input id="ReportHost" type="radio" name="ReportType" value="host" title="Generate report on HOST" checked="checked" />Host
<input id="ReportHostGroup" type="radio" name="ReportType" value="hostgroup" title="Generate report on GROUP" />Host Group
</p>
</td><td align="center" valign="top" width="110">
<center><?php echo $z_user; ?> <a href="logout.php">Logout</a></center>
</td></tr>
<tr><td valign="middle" align="left">
</td><td valign="center" align="left" width="70%" height="30">
<p id="p_ReportHost">
<label for="s_ReportHost" class="error">Please select your host</label>
<select id="s_ReportHost" name="HostID" width="350" style="width: 350px" title="Please select host" required>
<option value="">-- Select host --</option>
<?php
ReadArray($hosts);
?>
</select>
</p>
<p id="p_ReportHostGroup">
<select id="s_ReportHostGroup" name="GroupID" width="350" style="width: 350px" title="Please select hostgroup" >
<option value="">-- Select hostgroup --</option>
<?php
ReadArray($host_groups);
?>
</select>
</p>
<p>
<input type="checkbox" name="GraphsOn" value="yes" checked> Include graphs</input>
<input type="checkbox" name="ItemGraphsOn" value="yes"> Include graphed items</input>
<input type="checkbox" name="TriggersOn" value="yes"> Show triggers</input><BR/>
<input type="checkbox" name="ItemsOn" value="yes"> Show configured items status</input>
<input type="checkbox" name="TrendsOn" value="yes"> Show configured trends (SLA-ish)</input>
</p>
<p>
<input type="string" name="mygraphs2" style="font-size: 10px;" size=80 value="<?php echo $mygraphs; ?>"> ↑ Graphs to show (#.*# = all):</input>
<input type="string" name="myitems2" style="font-size: 10px;" size=80 value="<?php echo $myitemgraphs; ?>"> ↑ Items to graph (#.*# = all):</input>
</p>
</td><td valign="middle">
</td></tr>
<tr><td valign="middle" align="left">
<label for="ReportRange"><b>Report range</b></label>
</td><td valign="middle" align="left">
<p>
<input id="RangeLast" type="radio" name="ReportRange" value="last" title="Report on last activity" checked="checked" />Last
<input id="RangeCustom" type="radio" name="ReportRange" value="custom" title="Report using custom report range" />Custom
</p>
</td><td valign="middle">
</td></tr>
<tr><td valign="middle" align="left" height="50">
</td><td valign="middle" align="left" height="50">
<p id=p_RangeLast>
<select id="s_RangeLast" name="timePeriod" title="Please select range" required>
<option value="Hour">Hour</option>
<option value="Day">Day</option>
<option value="Week">Week</option>
<option value="Month">Month</option>
<option value="Year">Year</option>
</select>
</p>
<p id="p_RangeCustom">
<b>Start:</b><input name="startdate" id="datepicker_start" type="date" size="8" />at<input name="starttime" id="timepicker_start" type="time" size="5" />
<b>End:</b><input name="enddate" id="datepicker_end" type="date" size="8" />at<input name="endtime" id="timepicker_end" type="time" size="5" />
</p>
</td><td valign="bottom" align="middle">
<input type='submit' value='Generate'>
<span class="smalltext"><input type='checkbox' name='debug'>Debug</span>
<p><center>Version: <?php echo($version); ?></center></p>
</td></tr>
</table>
</form>
<br/>
<h2 id="h_OldReports">Old reports<br>
(click to show)</h2>
</center>
<div class="d_OldReports table-hidden">
<table id="OldReports" cellpadding="0" class="tablesorter">
<?php ListOldReports($pdf_report_dir); ?>
</table>
</div>
<script>
jQuery(function(){
jQuery('#datepicker_start').datetimepicker({
dayOfWeekStart: 1,
weeks: true,
format:'Y/m/d',
minDate:'-1971/01/01',// One year ago
maxDate:'+1970/01/01',// Today is maximum date calendar
onShow:function( ct ){
this.setOptions({
maxDate:jQuery('#datepicker_end').val()?jQuery('#datepicker_end').val():false
})
},
timepicker: false
});
jQuery('#datepicker_end').datetimepicker({
dayOfWeekStart : 1,
weeks: true,
format:'Y/m/d',
minDate:'-1971/01/01',// One year ago
maxDate:'+1970/01/01',// Today is maximum date calendar
onShow:function( ct ){
this.setOptions({
minDate:jQuery('#datepicker_start').val()?jQuery('#datepicker_start').val():false
})
},
timepicker: false
});
});
jQuery('#timepicker_start').datetimepicker({ datepicker:false, format:'H:i' });
jQuery('#timepicker_end').datetimepicker({ datepicker:false, format:'H:i' });
</script>
</body>
</html>