How to add a quick action to the dashboard
This example shows how to use the plugin to add a quick action to the quick action bar on the ispmanager dashboard, your quick action will open the Activity log:
This example assumes that you are logged into ispmanager as the super administrator (root).
- First, create an XML description file for the plugin. Go to the folder
/usr/local/mgr5/etc/xml
and create the fileispmgr_mod_mod_journal_block_dashboard.xml
. - Open this file and copy into it the code given
below:
<?xml version="1.0" encoding="UTF-8"?> <mgrdata> <handler name="journal_block_dashboard.sh" type="xml"> <event name="dashboard" after="yes"/> </handler> <lang name="ru"> <messages name="dashboard"> <msg name="taskbar_journal">Activity log</msg> </messages> </lang> </mgrdata>
- Create a handler: go to the
/usr/local/mgr5/addon
folder and create thejournal_block_dashboard.sh
file there. The handler file must be executable for the root user and group, so give the file permissions 750.
chmod 750 /usr/local/mgr5/addon/journal_block_dashboard.sh
- Open the file for editing and copy into it
the following code:
#!/bin/bash echo $(cat | sed -r 's/(<block[^\>]*name="taskbar"[^\>]*>)(.*)<\/block>/\1<toolbtn form="journal" name="journal" img="m-monitoring" spritesvg="yes"\/>\2<\/block>/g')
- To connect your new plugin to ispmanager, run the command
killall core
.
Details
Since the handler is connected using the <event name=“dashboard” after=“yes”/>
element in the plugin's XML description, this means that the handler will be executed after the main dashboard function handler is executed.
When executed, the handler will get the XML description of the dashboard page in STDIN. The handler processes the XML using the sed tool: it finds the <block element name=“taskbar”>
and inserts a quick action button at its beginning:
<toolbtn form=“journal” name=“journal” img=“m-monitoring” spritesvg=“yes”/>
The XML modified by the handler is then given to STDOUT and subsequently used by ispmanager to display the dashboard page.
You can read more about the structure of XML returned by handlers and about XML descriptions of plugins in Structure and functionality of plugins section.