Skip to content

Commit

Permalink
Merge pull request #1 from WardsParadox/master
Browse files Browse the repository at this point in the history
Added Pending Uninstalls Widget for Munki
  • Loading branch information
bochoven authored May 3, 2019
2 parents bca65d1 + d5e7ff7 commit 7ef5904
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -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) |
6 changes: 5 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
27 changes: 27 additions & 0 deletions managedinstalls_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
24 changes: 24 additions & 0 deletions managedinstalls_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


// ------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions provides.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
43 changes: 43 additions & 0 deletions views/pending_removals_munki_widget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="col-lg-4 col-md-6">

<div class="panel panel-default" id="pending-removals-munki-widget">
<div class="panel-heading" data-container="body" data-i18n="[title]managedinstalls.widget.pending_removals_munki.tooltip">
<h3 class="panel-title"><i class="fa fa-shopping-cart"></i>
<span data-i18n="managedinstalls.widget.pending_removals_munki.title"></span>
<list-link data-url="/module/managedinstalls/listing/#pending_removal"></list-link>
</h3>
</div>
<div class="list-group scroll-box"></div>
</div><!-- /panel -->

</div><!-- /col -->

<script>
$(document).on('appUpdate', function(e, lang) {
$.getJSON( appUrl + '/module/managedinstalls/get_pending_removals/munki', function( data ) {
var box = $('#pending-removals-munki-widget div.scroll-box').empty();
if(data.length){
$.each(data, function(i,d){
var badge = '<span class="badge pull-right">'+d.count+'</span>',
url = appUrl+'/module/managedinstalls/listing/'+d.name+'#pending_removal',
display_name = d.display_name || d.name;
box.append('<a href="'+url+'" class="list-group-item">'+display_name+' '+d.version+badge+'</a>');
});
}
else{
box.append('<span class="list-group-item">'+i18n.t('managedinstalls.no_updates_pending')+'</span>');
}
});
});
</script>

0 comments on commit 7ef5904

Please sign in to comment.