README.md 5.18 KB
Newer Older
remy's avatar
remy committed
1
# Jsonreader2
remy's avatar
remy committed
2

remy's avatar
remy committed
3
4
5
6
7
8
Jsonreader v2 is a PHP Web application parser for JSON files.

I am using it for reporting with a cron and SaltStack outputs in json format, but it can also parse other JSON files (check `include/toolReader.php` on how to do this).

This version 2 is a complete redesign from the MBB `portail_admin` project, that is to say with OOP, a model / database and a more modern UI.

remy's avatar
remy committed
9
It was a part of MBB `portail_admin` application (wrote mainly by my former co-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).
remy's avatar
remy committed
10

remy's avatar
remy committed
11
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`.
remy's avatar
remy committed
12
13
14

## Install

remy's avatar
remy committed
15
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.
remy's avatar
remy committed
16

remy's avatar
remy committed
17
Assuming you are using the easiest way.
remy's avatar
remy committed
18

remy's avatar
remy committed
19
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):
remy's avatar
remy committed
20

remy's avatar
remy committed
21
22
23
```bash
mkdir -p /var/www/html/exports
chmod -R 755 /var/www/html/exports
remy's avatar
remy committed
24
25
```

remy's avatar
remy committed
26
27
28
29
30
31
32
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`,
4. [Required] Add a crontab, eg: `*/30 * * * * /usr/local/sbin/check_salt_json 2>/dev/null`,
    and reload the service:

remy's avatar
remy committed
33
34
35
36
```bash
service cron reload
```

remy's avatar
remy committed
37
38
5. [Required] Install all needed packages for this web application:
  - `php-fpm` and reload your web server:
remy's avatar
remy committed
39
40
41
42
43
44
45
46
47

```bash
# for ubuntu/debian with php7.3 and apache:
apt install -y php-fpm
a2enmod proxy_fcgi setenvif
a2enconf php7.3-fpm
systemctl reload apache2
```

remy's avatar
remy committed
48
  - You also need a mysql/mariadb server:
remy's avatar
remy committed
49
50
51
52
53
54

```bash
apt install -y mariadb-server php-mysql
a2enmod proxy_fcgi setenvif
```

remy's avatar
remy committed
55
56
57
58
59
60
61
62
63
64
65
66
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`.
remy's avatar
remy committed
67
68
69
70
71

```bash
mysql -uroot -p < sql/jsonreader.sql
mysql -uroot -p jsonreader2 < sql/CReader.sql
mysql -uroot -p jsonreader2 < sql/ReaderTable.sql
remy's avatar
remy committed
72
mysql -uroot -p jsonreader2 < sql/CReaderPanel.sql
remy's avatar
remy committed
73
74
```

remy's avatar
remy committed
75
> For a jsonreader2 plugin version of `portail_admin`, please check `config/Plugin.php.sample`.
remy's avatar
remy committed
76
77
78
79
80

## Using SaltStack Formula

`Jsonreader2` is using some specific SaltStack formula + basic formula (`test.ping`, `service.status`, `osfinger` ...).

remy's avatar
remy committed
81
82
83
84
## 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`).

remy's avatar
remy committed
85
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 `Configuration` menu item (standalone version, `misc` otherwise).
remy's avatar
remy committed
86
87
88
89
90
91
92
93

### 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,
remy's avatar
remy committed
94
  - To check borgbackup report, take a look at [`borgbackup`](https://gitlab.mbb.univ-montp2.fr/saltstack-formulas/borgbackup) formula.
remy's avatar
remy committed
95
96

### Other Json reports
remy's avatar
remy committed
97

remy's avatar
remy committed
98
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`.
remy's avatar
remy committed
99

remy's avatar
remy committed
100
## Logrotate
remy's avatar
remy committed
101

remy's avatar
remy committed
102
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.