Skip to content

Commit

Permalink
Merge pull request #60 from NethServer/feat-6814
Browse files Browse the repository at this point in the history
Implement user counters in get-facts action
  • Loading branch information
DavidePrincipi authored Jan 24, 2024
2 parents 63fb2eb + a7b2399 commit d112e01
Show file tree
Hide file tree
Showing 2 changed files with 669 additions and 639 deletions.
30 changes: 30 additions & 0 deletions imageroot/actions/get-facts/10get_facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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

counter_script="""
podman exec mattermost-app mmctl --local --json user list | \
jq -c '[length, map(select(.is_bot == false)) | length]'
"""

try:
with subprocess.Popen(counter_script, stdout=subprocess.PIPE, shell=True, text=True) as fcounter:
total_users, active_users = json.load(fcounter.stdout)
except Exception as ex:
print(agent.SD_ERR, ex, file=sys.stderr)
total_users = 0
active_users = 0

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

0 comments on commit d112e01

Please sign in to comment.