diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..7febf93 --- /dev/null +++ b/README.MD @@ -0,0 +1,14 @@ +## managedinstalls Module for Munkireport-PHP + + +| Field | Type | +|-----------------|--------------------| +| id | int(10) | +| serial_number | varchar(255) | +| name | varchar(255) | +| display_name | varchar(255) | +| version | varchar(78) | +| size | int(11) | +| installed | int(11) | +| status | varchar(255) | +| type | varchar(255) | diff --git a/locales/en.json b/locales/en.json index e8687f5..c87c2b7 100644 --- a/locales/en.json +++ b/locales/en.json @@ -16,6 +16,10 @@ "pending_munki": { "title": "Pending Installs", "tooltip": "Pending installs for this week" + }, + "pending_removals_munki": { + "title": "Pending Removals", + "tooltip": "Pending removals for this week" } } -} +} \ No newline at end of file diff --git a/managedinstalls_controller.php b/managedinstalls_controller.php index 64490d2..bb9352e 100644 --- a/managedinstalls_controller.php +++ b/managedinstalls_controller.php @@ -70,6 +70,33 @@ public function get_pending_installs($type = "munki") // ------------------------------------------------------------------------ + /** + * Get pending removals + * + * + * @param string $type Type, munki or apple + **/ + public function get_pending_removals($type = "munki") + { + $out = array(); + if (! $this->authorized()) { + $out['error'] = 'Not authorized'; + } else { + $model = new Managedinstalls_model; + $hoursBack = 24 * 7; // Hours back + $out = array(); + + foreach ($model->get_pending_removals($type, $hoursBack) as $obj) { + $out[] = $obj; + } + } + + $obj = new View(); + $obj->view('json', array('msg' => $out)); + } + + // ------------------------------------------------------------------------ + /** * Get package statistics * diff --git a/managedinstalls_model.php b/managedinstalls_model.php index 613b961..24d330c 100644 --- a/managedinstalls_model.php +++ b/managedinstalls_model.php @@ -76,6 +76,30 @@ public function get_pending_installs($type, $hoursBack) ORDER BY count DESC"; return $this->query($sql, array($type)); } + // ------------------------------------------------------------------------ + + /** + * Get pending removals + * + * + * @param int $hours Amount of hours to look back in history + **/ + public function get_pending_removals($type, $hoursBack) + { + $fromdate = time() - 3600 * $hoursBack; + $updates_array = array(); + $filter = get_machine_group_filter('AND'); + $sql = "SELECT m.name, m.display_name, m.version, count(*) as count + FROM managedinstalls m + LEFT JOIN reportdata USING (serial_number) + WHERE status = 'pending_removal' + AND type = ? + $filter + AND reportdata.timestamp > $fromdate + GROUP BY name, display_name, version + ORDER BY count DESC"; + return $this->query($sql, array($type)); + } // ------------------------------------------------------------------------ diff --git a/provides.php b/provides.php index 104a3d9..b9e3849 100644 --- a/provides.php +++ b/provides.php @@ -8,6 +8,7 @@ 'get_failing' => array('view' => 'get_failing_widget'), 'pending_apple' => array('view' => 'pending_apple_widget'), 'pending_munki' => array('view' => 'pending_munki_widget'), + 'pending_removals_munki' => array('view' => 'pending_removals_munki_widget'), 'pending' => array('view' => 'pending_widget'), ), 'reports' => array( diff --git a/views/pending_removals_munki_widget.php b/views/pending_removals_munki_widget.php new file mode 100644 index 0000000..238cb50 --- /dev/null +++ b/views/pending_removals_munki_widget.php @@ -0,0 +1,43 @@ +
+ +
+ +
+ +

+ + +

+ +
+ +
+ +
+ +
+ +