Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inventory: add get-facts #19

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ images=()
repobase="${REPOBASE:-ghcr.io/nethserver}"
# Configure the image name
reponame="nethsecurity-controller"
controller_version=0.0.23
controller_version=0.0.24
promtail_version=2.7.1
loki_version=2.9.4
prometheus_version=2.50.1
Expand Down
34 changes: 34 additions & 0 deletions imageroot/actions/get-facts/10get_facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3

#
# Copyright (C) 2024 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-2.0-only
#

import json
import subprocess
import os
import sys
import agent

units = 0
users = 0
try:
p = subprocess.run(["/usr/bin/podman", "exec", "-ti", "vpn", "find", "/etc/openvpn/ccd", "-type", "f"], capture_output=True, text=True)
units = len(p.stdout.split("\n")) - 1
except Exception as ex:
print(agent.SD_ERR, ex, file=sys.stderr)
units = 0

try:
p = subprocess.run(["/usr/bin/podman", "exec", "-ti", "api", "sqlite3", "/nethsecurity-api/data/db.sqlite", "select count(*) from accounts;"], capture_output=True, text=True)
users = int(p.stdout.strip())
except Exception as ex:
print(agent.SD_ERR, ex, file=sys.stderr)
users = 0

json.dump({
"units": units,
"active_users": users,
"total_users": users
}, fp=sys.stdout)
Loading