Skip to content

Commit

Permalink
Merge pull request #19 from NethServer/inventory
Browse files Browse the repository at this point in the history
inventory: add get-facts
  • Loading branch information
gsanchietti authored Apr 12, 2024
2 parents d72ae6f + 3061649 commit 62c3b97
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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)

0 comments on commit 62c3b97

Please sign in to comment.