@@ -8,25 +8,34 @@ This version 2 is a complete redesign from the MBB `portail_admin` project, that
...
@@ -8,25 +8,34 @@ This version 2 is a complete redesign from the MBB `portail_admin` project, that
It was a part of MBB `portail_admin` application (wrote mainly by my former wo-worker [_Jimmy Lopez_](https://github.com/Falindir)), but is now a plugin of MBB `portail_admin` and can be used in a standalone version (default).
It was a part of MBB `portail_admin` application (wrote mainly by my former wo-worker [_Jimmy Lopez_](https://github.com/Falindir)), but is now a plugin of MBB `portail_admin` and can be used in a standalone version (default).
The first version was a single file; you can see it [here](https://github.com/remyd1/salt_states/tree/master/monitor_salt_json). In this first version, cron files were written into `/var/www/html/exports/YYYYMM/YYYYMMDD_type_of_export.json`. In this version 2, these files are located, by default, in `/var/www/html/exports/YYYYMM/DD/YYYYMMDD_type_of_export.json`.
The first version was a single file; you can see it [here](https://github.com/remyd1/salt_states/tree/master/monitor_salt_json). In this first version, cron files were written into `/var/www/html/exports/YYYYMM/YYYYMMDD_export-name.json`, then in `/var/www/html/exports/YYYYMM/YYYYMMDD_HH_export-name.json` and `/var/www/html/exports/YYYYMM/YYYYMMDD_HHMM_export-name.json`. In this version 2, files are located, by default, in `/var/www/html/exports/YYYYMM/DD/YYYYMMDD_HH_MM_export-name.json`.
## Install
## Install
Clone this repository in your document root and create the exports directory for json files `/var/www/html/exports`.
The easiest way is to configure your SaltStack master in a Web server and using JSON exports directly. Nevertheless, another option would be to mount on the SaltStack master a remote directory that would be used for JSON exports and web display. Finally, another option would be to configure `salt-api`, but I did not try this for that purpose.
Change TARGET by a minion ID in `check_salt_json` and copy `check_salt_json` to `/usr/local/sbin` and set it to be executable by root.
Assuming you are using the easiest way.
Add a crontab, eg:
1. [Required] Clone this repository in your WWW document root and create the exports directory for json files (web user must have access to the files created by the cron):
2. [Required] Copy `check_salt_json` to `/usr/local/sbin` and set it to be executable by root
3.[Optional] If you are using some additional [jsonreader2 plugins](#Specific-plugin-formulas), edit `check_salt_json`:
- Uncomment all the plugin you use, following "`# UNCOMMENT NEXT LINE(S) TO USE IT`",
- If you use the `check_disks` formula, change `TARGET` by a minion ID in `check_salt_json`. The `TARGET` minion is a minion who knows disk smart status of all physical minions through a mine called `mine_disks`,
5. [Required] Install all needed packages for this web application:
-`php-fpm` and reload your web server:
```bash
```bash
# for ubuntu/debian with php7.3 and apache:
# for ubuntu/debian with php7.3 and apache:
...
@@ -36,33 +45,58 @@ a2enconf php7.3-fpm
...
@@ -36,33 +45,58 @@ a2enconf php7.3-fpm
systemctl reload apache2
systemctl reload apache2
```
```
Of course, you also need a mysql/mariadb server:
- You also need a mysql/mariadb server:
```bash
```bash
apt install-y mariadb-server php-mysql
apt install-y mariadb-server php-mysql
a2enmod proxy_fcgi setenvif
a2enmod proxy_fcgi setenvif
```
```
Install the database using `*.sql` in `sql` directory, create mysql users and set it correctly in `config/Conf.php` and `sql/jsonreader.sql`.
6. [Required] Copy and edit files in `config/` directory:
```bash
cp config/Conf.php.sample config/Conf.php
vi config/Conf.php
cp config/Plugin.php.sample config/Plugin.php
vi config/Plugin.php
```
By default, only the mandatory sections are available (adjust your `$SECTIONS` to the plugins you installed).
7. [Required] Install the database using `*.sql` in `sql` directory; create mysql user and set it correctly in `config/Conf.php` and `sql/jsonreader.sql`.
```bash
```bash
mysql -uroot-p < sql/jsonreader.sql
mysql -uroot-p < sql/jsonreader.sql
mysql -uroot-p jsonreader2 < sql/CReader.sql
mysql -uroot-p jsonreader2 < sql/CReader.sql
mysql -uroot-p jsonreader2 < sql/ReaderTable.sql
mysql -uroot-p jsonreader2 < sql/ReaderTable.sql
mysql -uroot-p jsonreader2 < sql/CReaderPanel.sql
```
```
For a plugin version of `portail_admin`, please check `config/Plugin.php`.
> For a jsonreader2 plugin version of `portail_admin`, please check `config/Plugin.php.sample`.
## Using SaltStack Formula
## Using SaltStack Formula
`Jsonreader2` is using some specific SaltStack formula + basic formula (`test.ping`, `service.status`, `osfinger` ...).
`Jsonreader2` is using some specific SaltStack formula + basic formula (`test.ping`, `service.status`, `osfinger` ...).
### Specific formula
## Other JSON reports
To use other JSON reports, you need to clone the plugin (or the SaltStack formula), and then, uncomment or add specific report in `check_salt_json`. Then, add the jsonreader2 plugin title in `config/Plugin.php` (`$SECTION`).
For a new plugin from your own, or an update of jsonreader2, you will need to also add it in the database, and a PHP way to parse the JSON file. Adding it in the database can be done in the WebUI, using the _Misc_ menu items.
### Specific plugin formulas
All these plugins need to be set accordingly to your SaltStack configuration.
- To check disks smart status, take a look at [`check_disks`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_disks),
- To check services, take a look at the [`check_services`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_services) formula,
- To check D state processes, take a look at [`get_d_states`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/get_d_states) formula,
<!--- To check borgbackup report, take a look at [`borgbackup`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/borgbackup) formula,-->
### Other Json reports
- To check services, take a look at the [`check_services`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_services) formula.
It can also use web reports from [`website_checks`](https://gitlab.mbb.univ-montp2.fr/remy/website_checks). To use it, clone it in `/usr/local/website_checks`.
- To check disks, take a look at [`check_disks`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/check_disks).
- To check D state processes, take a look at [`get_d_states`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas) formula.
## Other Json reports
## Logrotate
It can also use web reports from [`website_checks`](https://gitlab.mbb.univ-montp2.fr/remy/website_checks).
The `/var/www/html/exports/` may grow quickly. A `logrotate` file is available in `utils/` directory. If you want to use it, copy it to `/etc/logrotate.d/checkjson` and reload the service.
####################### CHECKING SERVICES FROM PILLAR hosts.sls ######################
####################### CHECKING SERVICES FROM PILLAR hosts.sls #####################
/usr/bin/salt '*' state.sls check_services -t 10 --out=json --static |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_services.json
# UNCOMMENT NEXT LINE TO USE IT
#/usr/bin/salt '*' state.sls check_services -t 10 --out=json --static |grep -v " did not respond. No job will be sent." > ${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_services.json
############################ CHECKING D STATES PROCESSES #############################
############################ CHECKING D STATES PROCESSES ############################
salt '*' cmd.run "/usr/local/sbin/get_d_states"--static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_dstates.json
# UNCOMMENT NEXT LINE TO USE IT
#salt '*' cmd.run "/usr/local/sbin/get_d_states" --static --out=json |grep -v " did not respond. No job will be sent." > ${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_dstates.json
################################## DISK USAGE ########################################
################################## DISK USAGE #######################################
/usr/bin/salt '*' disk.percent --out=json --static |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_disks.json
/usr/bin/salt '*' disk.percent --out=json --static |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_disks_usage.json
#salt '*' cmd.run "if [ -f /sbin/zfs ] || [ -f /usr/local/sbin/zfs ]; then zpool status -x; fi" --static --out=json | grep -v " did not respond. No job will be sent." > $JSON_EXPORT_PATH/$SUBDIR/"$DATE"_zpool.json
# Adding d state process check. Otherwise, it will be overloaded with additionnal D state processes
################################# ZPOOL STATUS ######################################
# TODO: using salt zpool module
# TODO: using salt zpool module
salt '*' cmd.run "/bin/bash -c \"if \[ -f /sbin/zfs \] || \[ -f /usr/local/sbin/zfs \]; then if \\\[\\\`/usr/local/sbin/get_d_states count\\\` == 0 \\\]; then zpool status -x; else echo \\\"D states processes have been found\\\"; fi; fi\""--static--out=json | grep-v" did not respond. No job will be sent.">$JSON_EXPORT_PATH/$SUBDIR/"$DATE"_zpool.json
# UNCOMMENT NEXT LINE TO USE IT
#salt '*' cmd.run "/bin/bash -c \"if \[ -f /sbin/zfs \] || \[ -f /usr/local/sbin/zfs \]; then if \\\[ \\\`/usr/local/sbin/get_d_states count\\\` == 0 \\\]; then zpool status -x; else echo \\\"D states processes have been found\\\"; fi; fi\"" --static --out=json | grep -v " did not respond. No job will be sent." > $JSON_EXPORT_PATH/$SUBDIR/"$DATE"_zpool.json
## old way, without D state process checking (it may be overloaded with additionnal D state processes):
#salt '*' cmd.run "if [ -f /sbin/zfs ] || [ -f /usr/local/sbin/zfs ]; then zpool status -x; fi" --static --out=json | grep -v " did not respond. No job will be sent." > $JSON_EXPORT_PATH/$SUBDIR/"$DATE"_zpool.json
salt '*' grains.get osfinger --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_osversion.json
salt '*' grains.get osfinger --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_osversion.json
salt '*' grains.get biosreleasedate --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_biosdate.json
salt '*' grains.get biosreleasedate --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_biosdate.json
salt '*' grains.get saltversion --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_saltversion.json
salt '*' grains.get saltversion --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_saltversion.json
salt '*' grains.get kernelrelease --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_kernelversion.json
salt '*' grains.get kernelrelease --static--out=json |grep -v" did not respond. No job will be sent.">${JSON_EXPORT_PATH}/${SUBDIR}/"${DATE}"_kernelversion.json