-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.php
53 lines (38 loc) · 1.37 KB
/
demo.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
<?php
require('class.NagiosInventory.php' );
$ni = new NagiosInventory(getcwd().'\objects.cache');
//All hosts
//print_r($ni->GetObjects()->host); die();
//All commands
//print_r($ni->GetObjects()->command); die();
// Print as csv-file
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=nagios-inventory.csv");
header("Pragma: no-cache");
header("Expires: 0");
$hosts = $ni->Compose();
foreach ($hosts as $hostname => $stdHost) {
$h = $stdHost->host;
if(!isset($stdHost->service)) continue;
// Fix some variables before print
$hostgroups = isset($stdHost->hostgroups) ? implode($stdHost->hostgroups,",") : "-";
$alias = isset($h->alias) && $h->alias != "" ? $h->alias : "-";
foreach ($stdHost->service as $s) {
// Fix some variables before print
$parameters = isset($s->check_command_parameters) && $s->check_command_parameters != "" ? $s->check_command_parameters : "-";
$notes_url = isset($s->notes_url) && $s->notes_url != "" ? $s->notes_url : "-";
// Print host stuff
echo $hostgroups.";";
echo $h->host_name.";";
echo $alias.";";
echo $h->address.";";
// Print service stuff
echo $s->service_description.";";
echo $s->check_command_base.";";
echo $parameters.";";
echo $s->check_command_line.";";
echo $s->contact_groups.";";
echo $s->notification_period.";";
echo $notes_url;
echo "\r\n";
} }