From cf20f42d762a9b8f4aca0d3a2c083e108549a872 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Thu, 23 Nov 2023 16:44:57 +0100 Subject: [PATCH] add top shellcmd plugin --- config/config_defaults.php | 3 ++ .../plugins/shellcmd/top/config.json | 7 +++ .../deployment/plugins/shellcmd/top/info.json | 11 +++++ .../plugins/shellcmd/top/plugin.php | 47 +++++++++++++++++++ .../deployment/plugins/shellcmd/top/render.js | 42 +++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 public_html/deployment/plugins/shellcmd/top/config.json create mode 100644 public_html/deployment/plugins/shellcmd/top/info.json create mode 100644 public_html/deployment/plugins/shellcmd/top/plugin.php create mode 100644 public_html/deployment/plugins/shellcmd/top/render.js diff --git a/config/config_defaults.php b/config/config_defaults.php index 6c7cd6e3..3c516807 100644 --- a/config/config_defaults.php +++ b/config/config_defaults.php @@ -139,6 +139,9 @@ return [ 'processes'=>[ 'enabled'=>1, ], + 'top'=>[ + 'enabled'=>1, + ], ], ], diff --git a/public_html/deployment/plugins/shellcmd/top/config.json b/public_html/deployment/plugins/shellcmd/top/config.json new file mode 100644 index 00000000..9ea4596c --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/config.json @@ -0,0 +1,7 @@ +{ + "command": "top -b -n 1 | head -20", + "icon": "fa-solid fa-arrow-up-wide-short", + "interval": 5000, + "window-cols": 50, + "window-lines": 30 +} \ No newline at end of file diff --git a/public_html/deployment/plugins/shellcmd/top/info.json b/public_html/deployment/plugins/shellcmd/top/info.json new file mode 100644 index 00000000..ea2363aa --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/info.json @@ -0,0 +1,11 @@ +{ + "name": "Top", + "description": "Show top processes", + "author": "Axel Hahn; University of Bern; Institute for Medical education", + + "version": "1.0", + "date": "2023-11-23", + "url": "[included]", + "license": "GNU GPL 3.0" +} + diff --git a/public_html/deployment/plugins/shellcmd/top/plugin.php b/public_html/deployment/plugins/shellcmd/top/plugin.php new file mode 100644 index 00000000..2b64044c --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/plugin.php @@ -0,0 +1,47 @@ +<?php +/** + * + * SHELLCMD PLUGIN :: top + * + * ---------------------------------------------------------------------- + * 2023-11-23 axel.hahn@unibe.ch + */ +class shellcmd_top { + /** + * @var fallback command line to exectute; command in config.josn has priority + */ + protected $_command="top -b -n 1 | head -20"; + + /** + * constructor ... returns command + * @return string + */ + public function __constructor(){ + return $this->getCommand(); + } + + /** + * get command + * @return string + */ + public function getCommand(){ + return $this->_command; + } + + /** + * parse output and extract wanted values in section "data" + * @return array + */ + public function parsedata($aResult){ + $aResult['data']=[ + 'count'=>count($aResult['output'])-1, + ]; + return $aResult; + } + +} +/* + +EXAMPLE OUTPUT +... +*/ \ No newline at end of file diff --git a/public_html/deployment/plugins/shellcmd/top/render.js b/public_html/deployment/plugins/shellcmd/top/render.js new file mode 100644 index 00000000..9b014784 --- /dev/null +++ b/public_html/deployment/plugins/shellcmd/top/render.js @@ -0,0 +1,42 @@ +/** + * + * @param {array} aData + * @returns + */ + +/** + * callback function for ubd: render html code + * @param {array} aData json object + * @returns {string} + */ +function top_render(aData){ + var sReturn=''; + sReturn='<span style="float: right">'+aData['time']+'</span>'; // +' '+aData['command']+'</span>'; + if(aData['data']['count']==0){ + sReturn+='No activity<br><br>Command:<br>' + +aData['command']; + } else { + sReturn+='<pre>'; + for(var i=0; i<aData['output'].length; i++){ + // sReturn+='<div>'+aData['output'][i]+"</div>"; + sReturn+=aData['output'][i]+"<br>"; + } + sReturn+='</pre>'; + } + return sReturn; +} + +function top_init(){ + oUbdLoad=new ubd( + { + "domid": "divPluginshellcmdtop", + "url": "/deployment/plugins/shellcmd/getdata.php?plugin=top", + "renderer": top_render, + "ttl": 5, + } + ); + // oUbdLoad.render('waiting for first data...'); + oUbdLoad.update(); +} + +window.setTimeout("top_init()", 200); \ No newline at end of file -- GitLab