Skip to content
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 src/confd/yang/confd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ MODULES=(
"[email protected]"
"[email protected]"
"[email protected]"
"infix-system@2025-01-25.yang"
"infix-system@2025-04-29.yang"
"[email protected]"
"[email protected]"
"[email protected]"
Expand Down
97 changes: 97 additions & 0 deletions src/confd/yang/confd/infix-system.yang
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ module infix-system {
contact "[email protected]";
description "Infix augments and deviations to ietf-system.";

revision 2025-04-29 {
description "Add services status.";
reference "internal";
}

revision 2025-01-25 {
description "Add DNS resolver status.";
reference "internal";
Expand Down Expand Up @@ -412,6 +417,98 @@ module infix-system {
}
}
}

container services {
description "List of monitored system services (processes)";
config false;

list service {
description "Tracked system service processes.";

leaf pid {
type uint32;
description "Process ID (PID) of the service.";
}

leaf name {
type string;
description "Name of the service or process.";
}

leaf description {
type string;
description
"Short description of the service.";
}

leaf status {
type enumeration {
enum halted {
description "Service is halted.";
}
enum missing {
description "Service files or dependencies are missing.";
}
enum crashed {
description "Service has crashed.";
}
enum stopped {
description "Service has been manually stopped.";
}
enum busy {
description "Service is busy.";
}
enum restart {
description "Service is restarting.";
}
enum conflict {
description "Service has a conflict preventing start.";
}
enum unknown {
description "Service is in an unknown state.";
}
enum done {
description "Service task has completed.";
}
enum failed {
description "Service task has failed.";
}
enum active {
description "Run/task type service is active.";
}
enum stopping {
description "Service is in the process of stopping.";
}
enum teardown {
description "Service is performing teardown operations.";
}
enum setup {
description "Service is setting up.";
}
enum cleanup {
description "Service is cleaning up.";
}
enum paused {
description "Service is paused.";
}
enum waiting {
description "Service is waiting for conditions.";
}
enum starting {
description "Service is starting.";
}
enum running {
description "Service is running.";
}
enum dead {
description "Service process is dead.";
}
}
description
"Detailed current status of the process.";
}
}
}
}

deviation "/sys:system/sys:hostname" {
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions src/klish-plugin-infix/xml/infix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@
</SWITCH>
</COMMAND>

<COMMAND name="services" help="Show system services">
<ACTION sym="script">
show services
</ACTION>
</COMMAND>

<COMMAND name="software" help="Show software info">
<SWITCH name="optional" min="0" max="1">
<COMMAND name="name" help="Show detailed info about a partition">
Expand Down
13 changes: 13 additions & 0 deletions src/show/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ def software(args: List[str]) -> None:
else:
print("Too many arguments provided. Only one name is expected.")

def services(args: List[str]) -> None:
data = run_sysrepocfg("/ietf-system:system-state/infix-system:services")
if not data:
print("No service data retrieved.")
return

if RAW_OUTPUT:
print(json.dumps(data, indent=2))
return

cli_pretty(data, f"show-services")

def routes(args: List[str]):
ip_version = args[0] if args and args[0] in ["ipv4", "ipv6"] else "ipv4"

Expand Down Expand Up @@ -186,6 +198,7 @@ def execute_command(command: str, args: List[str]):
'ntp': ntp,
'routes': routes,
'lldp': lldp,
'services' : services,
'software' : software,
'stp': stp,
'wifi': wifi
Expand Down
47 changes: 47 additions & 0 deletions src/statd/python/cli_pretty/cli_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ class PadNtpSource:
poll = 14


class PadService:
name = 16
status = 8
pid = 8
description = 40


class PadWifiScan:
ssid = 40
encryption = 30
Expand Down Expand Up @@ -1507,6 +1514,42 @@ def show_software(json, name):
slot.print()


def show_services(json):
if not json.get("ietf-system:system-state", "infix-system:services"):
print("Error, cannot find infix-system:services")
sys.exit(1)

services_data = get_json_data({}, json, 'ietf-system:system-state', 'infix-system:services')
services = services_data.get("service", [])

hdr = (f"{'NAME':<{PadService.name}}"
f"{'STATUS':<{PadService.status}}"
f"{'PID':>{PadService.pid -1}}"
f" {'DESCRIPTION'}")
print(Decore.invert(hdr))

for svc in services:
name = svc.get('name', '')
status = svc.get('status', '')
pid = svc.get('pid', 0)
description = svc.get('description', '')

if status in ('running', 'active', 'done'):
status_str = Decore.green(status)
elif status in ('crashed', 'failed', 'halted', 'missing', 'dead', 'conflict'):
status_str = Decore.red(status)
else:
status_str = Decore.yellow(status)

pid_str = str(pid) if pid > 0 else '-'

row = f"{name:<{PadService.name}}"
row += f"{status_str:<{PadService.status + 9}}"
row += f"{pid_str:>{PadService.pid}}"
row += f" {description}"
print(row)


def show_hardware(json):
if not json.get("ietf-hardware:hardware"):
print("Error, top level \"ietf-hardware:component\" missing")
Expand Down Expand Up @@ -2496,6 +2539,8 @@ def main():
subparsers.add_parser('show-routing-table', help='Show the routing table') \
.add_argument('-i', '--ip', required=True, help='IPv4 or IPv6 address')

subparsers.add_parser('show-services', help='Show system services')

subparsers.add_parser('show-software', help='Show software versions') \
.add_argument('-n', '--name', help='Slotname')

Expand Down Expand Up @@ -2528,6 +2573,8 @@ def main():
show_routing_table(json_data, args.ip)
elif args.command == "show-software":
show_software(json_data, args.name)
elif args.command == "show-services":
show_services(json_data)

else:
print(f"Error, unknown command '{args.command}'")
Expand Down
19 changes: 19 additions & 0 deletions src/statd/python/yanger/ietf_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ def add_platform(out):

insert(out, "platform", platform)

def add_services(out):
data = HOST.run_json(["initctl", "-j"], [])
services = []

for d in data:
if "pid" not in d or "status" not in d or "identity" not in d or "description" not in d:
continue

entry = {
"pid": d["pid"],
"name": d["identity"],
"status": d["status"],
"description": d["description"]
}
services.append(entry)

insert(out, "infix-system:services", "service", services)

def add_software(out):
software = {}
try:
Expand Down Expand Up @@ -291,5 +309,6 @@ def operational():
add_dns(out_state)
add_clock(out_state)
add_platform(out_state)
add_services(out_state)

return out
24 changes: 24 additions & 0 deletions test/case/statd/system/cli/show-services
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
NAME STATUS PID DESCRIPTION
udevd running 1185 Device event daemon (udev)
dbus running 2248 D-Bus message bus daemon
confd running 3039 Configuration daemon
netopeer running 3548 NETCONF server
dnsmasq running 2249 DHCP/DNS proxy
tty:hvc0 running 3559 Getty on hvc0
iitod running 2340 LED daemon
klishd running 3560 CLI backend daemon
mdns-alias running 3617 mDNS alias advertiser
mstpd stopped - Spanning Tree daemon
rauc running 3564 Software update service
resolvconf done - Update DNS configuration
statd running 3472 Status daemon
staticd running 3653 Static routing daemon
syslogd running 2241 System log daemon
watchdogd running 2242 System watchdog daemon
zebra running 3587 Zebra routing daemon
mdns running 3616 Avahi mDNS-SD daemon
chronyd running 3618 Chrony NTP v3/v4 daemon
lldpd running 3633 LLDP daemon (IEEE 802.1ab)
nginx running 3635 Web server
rousette running 3636 RESTCONF server
sshd running 3641 OpenSSH daemon
Loading