diff --git a/README.md b/README.md index 92bfaaa..ad79c5f 100755 --- a/README.md +++ b/README.md @@ -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 @@ -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 \ No newline at end of file diff --git a/locales/en.json b/locales/en.json index 25fa2ed..26d25ef 100644 --- a/locales/en.json +++ b/locales/en.json @@ -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" } diff --git a/munkiinfo_controller.php b/munkiinfo_controller.php index 858b70c..d310210 100644 --- a/munkiinfo_controller.php +++ b/munkiinfo_controller.php @@ -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()) { @@ -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(); diff --git a/provides.yml b/provides.yml index c779a5a..d7a0dff 100755 --- a/provides.yml +++ b/provides.yml @@ -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 \ No newline at end of file + 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 \ No newline at end of file diff --git a/views/munkiinfo_clientidentifier_widget.yml b/views/munkiinfo_clientidentifier_widget.yml new file mode 100755 index 0000000..c1f6752 --- /dev/null +++ b/views/munkiinfo_clientidentifier_widget.yml @@ -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 \ No newline at end of file diff --git a/views/munkiinfo_logfile_widget.yml b/views/munkiinfo_logfile_widget.yml new file mode 100755 index 0000000..b3edbf2 --- /dev/null +++ b/views/munkiinfo_logfile_widget.yml @@ -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 \ No newline at end of file diff --git a/views/munkiinfo_managedinstalldir_widget.yml b/views/munkiinfo_managedinstalldir_widget.yml new file mode 100755 index 0000000..81330f3 --- /dev/null +++ b/views/munkiinfo_managedinstalldir_widget.yml @@ -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 \ No newline at end of file diff --git a/views/munkiinfo_report.yml b/views/munkiinfo_report.yml new file mode 100755 index 0000000..19ec7bd --- /dev/null +++ b/views/munkiinfo_report.yml @@ -0,0 +1,7 @@ +row1: + munkiinfo_munkiprotocol: + munkiinfo_softwarerepourl: + munkiinfo_clientidentifier: +row2: + munkiinfo_logfile: + munkiinfo_managedinstalldir: diff --git a/views/munkiinfo_softwarerepourl_widget.yml b/views/munkiinfo_softwarerepourl_widget.yml new file mode 100755 index 0000000..f7871d5 --- /dev/null +++ b/views/munkiinfo_softwarerepourl_widget.yml @@ -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 \ No newline at end of file