Skip to content

Commit

Permalink
Add munkiinfo widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxudo committed Aug 30, 2024
1 parent 6019502 commit 6ba5488
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 41 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The following information is stored in the munkiinfo table:

_NOTE:_ the names line up with [Munki Preferences](https://github.com/munki/munki/wiki/Preferences) as such no description is given

Munki Preference Keys
------

* AppleSoftwareUpdatesOnly
* CatalogURL
Expand Down Expand Up @@ -46,9 +48,15 @@ _NOTE:_ the names line up with [Munki Preferences](https://github.com/munki/munk
* UseClientCertificate
* UseClientCertificateCNAsClientIdentifier


These are the only non-ManagedInstall preference values stored in this module

* AppleCatalogURL - This is the catalog that `/usr/sbin/softwareupdate` will use to find updates
* munkiprotocol - This is the url scheme for the `SoftwareRepoURL` key. This is used for widgets.
* middlewarename and middlewareversion - These are displayed only if middleware is installed. Version relies on a get_version() function in your middleware script.


Table Schema
------

munkiinfo_key - VARCHAR(255) - Munki preference key name
munkiinfo_value - VARCHAR(255) - Munki preference key value
8 changes: 6 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
"tooltip": "Munki protocol among all clients"
},
"protocol": "Protocol",
"reporttitle": "Munki Info",
"reporttitle": "Munki Info Report",
"softwarerepourl": "Software Repo URL",
"start": "Start",
"value": "Value"
"value": "Value",
"clientidentifier": "Munki ClientIdentifier",
"logfile": "Munki LogFile",
"managedinstalldir": "Munki ManagedInstallDir",
"softwarerepourl": "Munki SoftwareRepoURL"
}
95 changes: 58 additions & 37 deletions munkiinfo_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,32 @@ class munkiinfo_controller extends Module_controller
protected $module_path;
protected $view_path;


/*** Protect methods with auth! ****/
/*** Protect methods with auth! ****/
public function __construct()
{
// Store module path
// Store module path
$this->module_path = dirname(__FILE__);
$this->view_path = dirname(__FILE__) . '/views/';
}

/**
* Default method
*
* @author
**/
/**
* Default method
*
* @author
**/
public function index()
{
echo "You've loaded the munkiinfo module!";
}

/**
* undocumented function summary
*
* Undocumented function long description
*
* @param type var Description
* @return {11:return type}
*/
* undocumented function summary
*
* Undocumented function long description
*
* @param type var Description
* @return {11:return type}
*/
public function listing($value = '')
{
if (! $this->authorized()) {
Expand All @@ -48,37 +47,59 @@ public function listing($value = '')
$obj->view('munkiprotocol_listing', $data, $this->view_path);
}

/**
* Get Munki Protocol Statistics
*
* @author erikng
**/
/**
* Get Munki Protocol Statistics
*
* @author erikng
**/
public function get_protocol_stats()
{

if (! $this->authorized()) {
// die('Authenticate first.'); // Todo: return json
$out['error'] = 'Not authorized';
}

$queryobj = new munkiinfo_model();
$sql = "SELECT COUNT(1) as total,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'http' THEN 1 END) AS http,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'https' THEN 1 END) AS https,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'localrepo' THEN 1 END) AS localrepo
FROM munkiinfo
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();
$obj = new View();
$obj->view('json', array('msg' => current($queryobj->query($sql))));
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'http' THEN 1 END) AS http,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'https' THEN 1 END) AS https,
COUNT(CASE WHEN `munkiinfo_key` = 'munkiprotocol' AND `munkiinfo_value` = 'localrepo' THEN 1 END) AS localrepo
FROM munkiinfo
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter();

$queryobj = new Munkiinfo_model;
jsonView($queryobj->query($sql)[0]);
}

/**
* Get munki preferences for serial_number
*
* @param string $serial serial number
* @author clburlison
**/
/**
* Get data for scroll widget
*
* @return void
* @author tuxudo
**/
public function get_scroll_widget($column)
{
// Remove non-column name characters
$column = preg_replace("/[^A-Za-z0-9_\-]]/", '', $column);

$sql = "SELECT `munkiinfo_value` as ".$column.",
COUNT(`munkiinfo_value`) AS count
FROM munkiinfo
LEFT JOIN reportdata USING (serial_number)
".get_machine_group_filter()."
AND `munkiinfo_key` = '".$column."' AND `munkiinfo_value` <> '' AND `munkiinfo_value` IS NOT NULL
GROUP BY `munkiinfo_value`
ORDER BY count DESC";

$queryobj = new Munkiinfo_model;
jsonView($queryobj->query($sql));
}

/**
* Get munki preferences for serial_number
*
* @param string $serial serial number
* @author clburlison
**/
public function get_data($serial = '')
{
$out = array();
Expand Down
14 changes: 13 additions & 1 deletion provides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ listings:
munkiinfo:
view: munkiinfo_listing
i18n: munkiinfo.listing
reports:
mosyle:
view: munkiinfo_report
i18n: munkiinfo.reporttitle
widgets:
munkiinfo_munkiprotocol:
view: munkiinfo_munkiprotocol_widget
view: munkiinfo_munkiprotocol_widget
munkiinfo_softwarerepourl:
view: munkiinfo_softwarerepourl_widget
munkiinfo_clientidentifier:
view: munkiinfo_clientidentifier_widget
munkiinfo_logfile:
view: munkiinfo_logfile_widget
munkiinfo_managedinstalldir:
view: munkiinfo_managedinstalldir_widget
9 changes: 9 additions & 0 deletions views/munkiinfo_clientidentifier_widget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: scrollbox
widget_id: munkiinfo-clientidentifier-widget
api_url: /module/munkiinfo/get_scroll_widget/ClientIdentifier
i18n_title: munkiinfo.clientidentifier
icon: fa-person
listing_link: /show/listing/munkiinfo/munkiinfo
search_key: ClientIdentifier
badge: count
i18n_empty_result: no_data
9 changes: 9 additions & 0 deletions views/munkiinfo_logfile_widget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: scrollbox
widget_id: munkiinfo-logfile-widget
api_url: /module/munkiinfo/get_scroll_widget/LogFile
i18n_title: munkiinfo.logfile
icon: fa-tree
listing_link: /show/listing/munkiinfo/munkiinfo
search_key: LogFile
badge: count
i18n_empty_result: no_data
9 changes: 9 additions & 0 deletions views/munkiinfo_managedinstalldir_widget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: scrollbox
widget_id: munkiinfo-managedinstalldir-widget
api_url: /module/munkiinfo/get_scroll_widget/ManagedInstallDir
i18n_title: munkiinfo.managedinstalldir
icon: fa-folder-open
listing_link: /show/listing/munkiinfo/munkiinfo
search_key: ManagedInstallDir
badge: count
i18n_empty_result: no_data
7 changes: 7 additions & 0 deletions views/munkiinfo_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
row1:
munkiinfo_munkiprotocol:
munkiinfo_softwarerepourl:
munkiinfo_clientidentifier:
row2:
munkiinfo_logfile:
munkiinfo_managedinstalldir:
9 changes: 9 additions & 0 deletions views/munkiinfo_softwarerepourl_widget.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: scrollbox
widget_id: munkiinfo-softwarerepourl-widget
api_url: /module/munkiinfo/get_scroll_widget/SoftwareRepoURL
i18n_title: munkiinfo.softwarerepourl
icon: fa-file-archive-o
listing_link: /show/listing/munkiinfo/munkiinfo
search_key: SoftwareRepoURL
badge: count
i18n_empty_result: no_data

0 comments on commit 6ba5488

Please sign in to comment.