Metadata-Version: 2.4
Name: monitoring-app-reporter
Version: 1.0.0
Summary: Upload an Inferyx user list to S3 on a schedule, for a monitoring-app console that cannot reach this server
Author-email: Inferyx DevOps <devops@inferyx.com>
License-Expression: LicenseRef-Proprietary
Keywords: inferyx,users,s3,monitoring-app
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: POSIX :: Linux
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31.0
Requires-Dist: boto3>=1.34.0
Requires-Dist: cryptography>=42.0.0
Dynamic: license-file

# monitoring-app-reporter

Uploads the Inferyx user list of **this** server (e.g. DEV) to S3 at the times you
choose. A [monitoring-app](https://pypi.org/project/monitoring-app/) console on another
server that cannot reach this one (e.g. PROD in another AWS account) reads the file and
mails it with its user export.

Small on purpose: `requests`, `boto3`, `cryptography`. No console, no web server, no
open port, nothing running between uploads — only a systemd timer.

## Install (on the server whose users are shared)

```bash
H=/opt/monitoring-app-reporter
sudo useradd --system --home-dir "$H" --shell /usr/sbin/nologin inferyx 2>/dev/null || true
sudo mkdir -p "$H" && sudo chown inferyx:inferyx "$H"
sudo -u inferyx python3 -m venv "$H/.venv"
sudo -u inferyx "$H/.venv/bin/pip" install monitoring-app-reporter
CMD="$H/.venv/bin/monitoring-app-reporter"

sudo -u inferyx $CMD configure --api-url https://<this-host>/framework \
    --bucket <bucket> --s3-key monitoring-app/platform-users/dev.json --label DEV --region ap-south-1
sudo -u inferyx $CMD set-token          # paste the Inferyx admin token; stored encrypted
sudo -u inferyx $CMD run --dry-run      # fetch and count only
sudo -u inferyx $CMD run                # upload once
sudo $CMD install-timer --times 08:30,20:30   # daily at these times (IST)
```

## Schedule

| Want | Command |
|---|---|
| Daily at 08:30 and 20:30 IST | `sudo $CMD install-timer --times 08:30,20:30` |
| Weekdays only | `sudo $CMD install-timer --on-calendar 'Mon..Fri *-*-* 08:30 Asia/Kolkata'` |
| Change the times | run `install-timer` again with the new times |
| Next run / last result | `$CMD status` |
| Run now | `sudo systemctl start monitoring-app-reporter.service` |
| Remove | `sudo $CMD uninstall-timer` |

Upload a few minutes **before** the console's export schedule. The console does not
mail an upload older than `MONITORING_APP_USERS_S3_MAX_AGE_HOURS` (26 h); raise it if
you upload less than daily.

## What is uploaded

One JSON object (SSE-S3 encrypted): first / last name, user name, email, created /
updated by and on, groups, roles, last login, active flag — all users, active and
inactive. The token is never uploaded. A list of 0–1 users (Inferyx sometimes answers
with only the token's own user) is never uploaded, so a bad answer cannot replace a
good file.

## AWS

- This server's EC2 role: `s3:PutObject` on `arn:aws:s3:::<bucket>/<key>`.
- The bucket (in the console's account) allows that role to put that object; Object
  Ownership *Bucket owner enforced*, Block Public Access on.
- The console's EC2 role: `s3:GetObject` on the same object.

Files: `/opt/monitoring-app-reporter/config.env` (settings), `secrets/` (key and
encrypted token, owner-only).
