-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmunkireportinfo_controller.php
executable file
·126 lines (117 loc) · 3.36 KB
/
munkireportinfo_controller.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
<?php
/**
* Munkireportinfo module class
*
* @package munkireport
* @author tuxudo
**/
class Munkireportinfo_controller extends Module_controller
{
/**
* Default method
*
* @author tuxudo
**/
public function index()
{
echo "You've loaded the munkireportinfo module!";
}
/*** Protect methods with auth! ****/
public function __construct()
{
// Store module path
$this->module_path = dirname(__FILE__);
}
/**
* Get MunkiReport Protocol Statistics
*
* @author erikng, tweaked by tuxudo
**/
public function get_protocol_stats()
{
jsonView(
Munkireportinfo_model::selectRaw("COUNT(CASE WHEN baseurl LIKE 'http://%' THEN 1 END) AS http")
->selectRaw("COUNT(CASE WHEN baseurl LIKE 'https://%' THEN 1 END) AS https")
->filter()
->first()
->toLabelCount()
);
}
/**
* Get munki versions
* Taken from munkireport controller
*
**/
public function get_versions()
{
jsonView(
Munkireportinfo_model::selectRaw('version, count(*) AS count')
->filter()
->groupBy('version')
->orderBy('count', 'desc')
->get()
->toArray()
);
}
/**
* Get statistics
* Taken from munkireport controller
*
* @param integer $hours Number of hours to get stats from
**/
public function get_stats($hours = 24)
{
$timestamp = time() - 60 * 60 * (int) (24 * 7);
jsonView(
Munkireportinfo_model::selectRaw('sum(error_count > 0) as error, sum(warning_count > 0) as warning')
->filter()
->where('munkireportinfo.start_time', '>', $timestamp)
->first()
->toLabelcount()
);
}
public function get_errors($max = 5)
{
$timestamp = time() - 60 * 60 * (int) (24 * 7);
jsonView(
Munkireportinfo_model::selectRaw('log_error, COUNT(*) as count')
->where('error_count', '>', 0)
->where('start_time', '>', $timestamp)
->filter()
->groupBy('log_error')
->orderBy('count', 'desc')
->limit($max)
->get()
->toArray()
);
}
public function get_warnings($max = 5)
{
$timestamp = time() - 60 * 60 * (int) (24 * 7);
jsonView(
Munkireportinfo_model::selectRaw('log_warning, COUNT(*) as count')
->where('warning_count', '>', 0)
->where('start_time', '>', $timestamp)
->filter()
->groupBy('log_warning')
->orderBy('count', 'desc')
->limit($max)
->get()
->toArray()
);
}
/**
* Retrieve data in json format
*
**/
public function get_data($serial_number)
{
jsonView(
Munkireportinfo_model::selectRaw('version, baseurl, passphrase, start_time, end_time, upload_size, error_count, warning_count, log_warning, log_error, reportitems, log_size, warning_log_size, error_log_size, log')
->where('munkireportinfo.serial_number', $serial_number)
->filter()
->get()
->toArray()
);
}
} // END class Munkireportinfo_model