-
Notifications
You must be signed in to change notification settings - Fork 24
MODS Server Monitor
This is a packaging of Php Server Monitor for Synology created with 'Mods Packager'.
This package comes with a WIZARDUI which prompt the user to collect parameters required to create a database for php Server Monitor. It comes therefore also with installation scripts that create this database. It also support nping, which does not require root access but must be installed via ipkg or opkg.
Php Server Monitor can be opened in a DSM iFrame (by default) or in a new window.
Find the source code here
In order to work on Synology, outside the standard root web folder (i.e: in the folder /var/packages/<...>/target), I had to patch the function 'psm_build_url' in the file src\includes\functions.inc.php.
Replace
$url = rtrim($url, '/');
by
$url = rtrim($url, '/') . '/index.php';
Php Server Monitor was using a path without the page name 'index.php' (Ex.= http:///webman/3rdparty/MODS_ServerMonitor/?&mod=server_status). And this only work if the path of the application is under the root web folder of Synology. Also, I couldn't use an htaccess as it is not supported anymore on Synology; The most recent DSM versions are indeed using nginx instead of apache.
Also, to not depend on the package Init_3rdparty usually required to run php pages outside the default web root, I am using the technique described here.
Take note that the default DB port of MariaDB, on Synology, is 3307 while the default port of mySQL is 2206. My package is configured to use MariaDB and its port 3307 by default.
Finally, note that when Server Monitor will run for the first time, it could fail to find the MySQL Drivers for PHP. This is because the adhoc extension is possibly not loaded by php. My CGI router is using the /etc/php/php.ini file. Open that file and check that you see find this: extension = pdo_mysql.so Once /etc/php/php.ini updated, execute in a ssh: sudo synoservicecfg --reload nginx
If you want Php Server Monitor to auto-update, create a "Scheduled Task" > "User-Defined Script" in the "Control Panel" > "Task Scheduler". Run it, e.g. every 15'. In the "Task Settings", use the command:
/usr/local/bin/php73 /var/packages/MODS_ServerMonitor/target/ui/cron/status.cron.php
phpServer Monitor offers three methods to test that a target is "online". Access on a web page (GET, POST, UPDATE, ... on a URL), connection on a service (an IP and a port) and ping (on an IP v4 or v6). Unfortunately, on Synology, one has to be granted root access in order to run ping. To workaround that constraint, my package is using nping if this one is installed in /opt/bin. It's really easy to install using ipkg or opkg.
I wanted to script the creation of the database required to install php Server Monitor and automate its configuration. For that purpose, I have added a WIZARDUI with two steps (i.e.: two screens) and installation scripts.
You can watch this video which illustrates the how-to here under.
Step 1
Right click on the root "Array" to add a first step with 'Database Information' as a title ("step_title": "Database Information") and "step validation" checked ("invalid_next_disabled": true). This last option will prevent the user to move to the next step if there is still a field not valid (All fields will be configured to be alphanumeric and non-blank. I.e.: mandatory).
This first step will be used to collect information to create the database. It will be a screen with 3 items (each one with a description and one or several fields. Reminder: all fields in the same item must have the same type).
Right click on the new "Array" and add 3 times "an item group":
- item group 1 is of type 'textfield' and will contain 2 subitems (I.e.: 2 text field to be filled)
- item group 2 is of type 'textfield' and will contain 1 subitem (I.e.: 1 text field to be filled)
- item group 3 is of type 'password' and will contain 1 subitem (I.e.: 1 password field to be filled)
The first item group contains:
- The name of the server hosting the database: a textfield with 'pkgwizard_server_name' as a Key, 'Server Name' as a Description and 'localhost' as a Default Value. It will also have validators to be mandatory and alphanumeric ("validator": {"vtype": "alphanum","allowBlank": false})
- The name of the database as you will see it in phpMyAdmin: a textfield with 'pkgwizard_db_Name' as a Key, 'Database Name' as a Description and 'phpservermon' as a default value. Use the same validators as above. To add this second textfield, right click on the last 'Array' (which already contains the textfield here above).
The second item group contains:
- The name of an Administrator account to be used to create the database: a textfield with 'pkgwizard_admin_account' as a Key, 'Account' as a Description and 'root' as a default value. Use the same validators as above.
The third item group contains:
- The password of the Administrator account here above: a password with 'pkgwizard_admin_password' as a Key and 'Password' as a Description. Only uncheck "Allow Blank" as a validator (Indeed any character can be used).
{
"step_title": "Database Information",
"invalid_next_disabled": false,
"items": [
{
"type": "textfield",
"desc": "Enter Database Server Information",
"subitems": [
{
"key": "pkgwizard_server_name",
"desc": "Server Name",
"defaultValue": "localhost"
},
{
"key": "pkgwizard_db_Name",
"desc": "Database Name",
"defaultValue": "phpservermon"
}
]
},
{
"type": "textfield",
"desc": "Enter Database Administrator account",
"subitems": [
{
"validator": {
"vtype": "alphanum",
"allowBlank": false
},
"defaultValue": "root",
"key": "pkgwizard_admin_account",
"desc": "Account"
}
]
},
{
"type": "password",
"desc": "Enter Database Administrator password",
"subitems": [
{
"validator": {
"vtype": "alphanum",
"allowBlank": false
},
"key": "pkgwizard_admin_password",
"desc": "Password"
}
]
}
]
}
Step 2
Right click on the root "Array" to add a second step with 'ServerMon Information' as a title ("step_title": "ServerMon Information") and "step validation" checked ("invalid_next_disabled": true).
This second step will be used to collect information to configure 'php Server Monitor'. It will be a screen with 2 items.
Right click on the new "Array" and add 2 times "an item group":
- item group 1 is of type 'textfield' and contains 1 subitem.
- item group 2 is of type 'textfield' and contains 1 subitem. (See NB bellow about this one)
The first item group contains:
- The name of an account that will be used by 'php Server Monitor' to access its DB: a textfield with 'pkgwizard_srvmon_account' as a Key, 'Account' as a Description and 'servermon' as a default value. Use the same validators as previously.
The second item group contains:
- The password for the account here above: a textfield with 'pkgwizard_srvmon_password' as a Key and 'Password' as a Description. Only uncheck "Allow Blank" as a validator (Indeed any character can be used).
{ "step_title": "ServerMon Information", "invalid_next_disabled": true, "items": [ { "type": "textfield", "desc": "Enter an account to access Server Monitor's Database", "subitems": [ { "validator": { "vtype": "alphanum", "allowBlank": false }, "key": "pkgwizard_srvmon_account", "defaultValue": "servermon", "desc": "Account" } ] }, { "type": "textfield", "desc": "Enter a Password for this account (will be visible in Server Monitor's config.php)", "subitems": [ { "validator": { "vtype": "alphanum", "allowBlank": false }, "key": "pkgwizard_srvmon_password", "desc": "Password" } ] } ] }
NB. For some reasons, with my current version of DSM, I may not have several 'password' fields in the wizard. E.g.: If I do have two password, the second one takes the same value as the first one ?! That's the reason why I am using a textfield in the second step to prompt for the password.
You can watch this video which illustrates the how-to here under.
I noticed that sometimes, the Wizard does not show when installing the package from my own SSPKS server. Solution: download the package and do a "manual install".