nextcloud / nextcloud/serverinfo

Adding custom metric

Open
#841 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
JavaScript
Stars
130
Forks
64
Avg merge
1d 1h
Merged PRs (30d)
49

Description

Hi! I would like to add LTE modem signal strength to the available data (metrics) provided on the page serverinfo.
I have a Python function which gets this data from LTE modem which can be run as modem_signal.py http://192.168.0.1 and provides the output like Orange PL LTE ▂▃▄.

#!/usr/bin/env python3

"""
Display 4G/5G modem signal strength using vertical bars and show operator + access mode.
Example usage:
python3 modem_signal.py http://admin:PASSWORD@192.168.0.1/
"""

from argparse import ArgumentParser
from huawei_lte_api.Connection import Connection
from huawei_lte_api.Client import Client
import re

SIGNAL_LEVELS = {
    0: "     ",
    1: "▂    ",
    2: "▂▃   ",
    3: "▂▃▄  ",
    4: "▂▃▄▅ ",
    5: "▂▃▄▅▇"
}

def parse_dbm(value):
    if value is None:
        return None
    match = re.search(r'-?\d+', str(value))
    return int(match.group()) if match else None

def get_signal_level(rsrp: int) -> int:
    if rsrp is None:
        return 0
    if rsrp >= -80:
        return 5
    elif rsrp >= -90:
        return 4
    elif rsrp >= -100:
        return 3
    elif rsrp >= -110:
        return 2
    elif rsrp >= -120:
        return 1
    else:
        return 0

def generate_signal_bars(level: int, total: int = 5) -> str:
    """
    Create a vertical bar chart (like a phone signal icon).
    Each bar grows higher from left to right.
    """
    result = []
    for row in range(total, 0, -1):
        line = ""
        for col in range(1, total + 1):
            if col <= level and row <= col:
                line += "▇ "
            else:
                line += "  "
        result.append(line.rstrip())
    return "\n".join(result)

def main():
    parser = ArgumentParser()
    parser.add_argument('url', type=str)
    parser.add_argument('--username', type=str)
    parser.add_argument('--password', type=str)
    args = parser.parse_args()

    with Connection(args.url, username=args.username, password=args.password) as connection:
        client = Client(connection)

        # Get signal and network info
        signal_info = client.device.signal()
        status_info = client.monitoring.status()
        network_type_raw = str(status_info.get('CurrentNetworkType', '0'))

        network_type_map = {
          '0': 'No Service',
          '1': 'GSM', '2': 'GPRS', '3': 'EDGE',
          '4': 'WCDMA', '5': 'HSDPA', '6': 'HSUPA', '7': 'HSPA',
          '8': 'TDSCDMA', '9': 'HSPA+',
          '10': 'EVDO Rev.0', '11': 'EVDO Rev.A', '12': 'EVDO Rev.B',
          '13': '1xRTT', '14': 'UMB', '15': '1xEVDV', '16': '3xRTT',
          '17': 'HSPA+ 64QAM', '18': 'HSPA+ MIMO',
          '19': 'LTE', '41': 'LTE CA',
          '101': 'NR5G NSA', '102': 'NR5G SA'
        }
        plmn_info = client.net.current_plmn()

        # Parse and determine values
        rsrp = parse_dbm(signal_info.get('rsrp'))
        rsrq = signal_info.get('rsrq')
        sinr = signal_info.get('sinr')

        level = get_signal_level(rsrp)
#        bars = generate_signal_bars(level)
        bars = SIGNAL_LEVELS[level]

        operator_name = plmn_info.get('FullName') or plmn_info.get('ShortName') or "Unknown"

        # Map internal mode codes (if any) to readable labels
        mode_map = {
           "LTE": "4G",
           "WCDMA": "3G",
           "GSM": "2G",
           "NR5G": "5G",
           "NR": "5G"
        }
        readable_mode = network_type_map.get(network_type_raw, f"Unknown ({network_type_raw})")

        # Display
        print(f"{operator_name} {readable_mode} {bars}")
#        print(bars)
#        print(f"\n  RSRP: {signal_info.get('rsrp')}")
#        if rsrq: print(f"  RSRQ: {rsrq}")
#        if sinr: print(f"  SINR: {sinr}")

if __name__ == "__main__":
    main()

What is the best way to embed it to the serverinfo page?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the serverinfo page and its existing metric entry points, then read modem_signal.py to understand the proposed LTE signal input and output. Determine how this data could be exposed and rendered on the page; done means the LTE modem signal strength is available as a serverinfo metric.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, python
Domain
observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.