Discovery¶
Discovery answers named questions about this host, called probes: which performance counters there are, and - as more modules gain probes - which databases a saved login can see or which scripts sit under the script root. A probe is asked, runs, answers, and nothing is kept. It is what the web UI’s pickers are filled from.
Discovery is not facts. Facts are an inventory an operator turns
on, set by set, that the core collects on a schedule, stores and can send to a
fleet server. A probe has no setting that turns it on and no schedule, and its
answer is never written to the fact document, a state report or a fleet
upload. The two share the record shape - a list of objects, each with an id -
and nothing else.
Every endpoint needs the discovery.run privilege, which only the built-in
full role (*) holds. facts.get does not imply it, and no wildcard short
of * covers it, so a role made for inventory readers or monitoring servers
gains nothing. Discovery is reachable over REST, the nscp test console and
the nscp discovery command only: NRPE, NSCA and
the other check transports cannot run a probe, because a probe is not a query.
List the probes¶
The probes the loaded modules answer now. A module that is not loaded answers nothing, so its probes are not listed.
| Key | Value |
|---|---|
| Verb | GET |
| Address | /api/v2/discovery |
| Privilege | discovery.run |
Request¶
GET /api/v2/discovery
Response¶
[
{
"name": "pdh.counters",
"kind": "detail",
"description": "The performance (PDH) counters on this host, for the counter picker",
"module": "CheckSystem",
"instance": "CheckSystem",
"url": "https://localhost:8443/api/v2/discovery/pdh.counters"
}
]
| Field | Meaning |
|---|---|
name |
The probe, dotted and lower case. |
kind |
presence (what is installed and running on the host) or detail (what a loaded module sees). |
description |
What the probe answers, from the module’s module.json. |
module |
The module that answers it. |
instance |
The alias that module was loaded under, or its name when it has none. A module loaded twice lists each probe once per instance. |
url |
Where to POST to run it. |
Example¶
curl -s -k -u admin https://localhost:8443/api/v2/discovery | python -m json.tool
Run a probe¶
Runs one probe now and returns what it found. A probe takes no arguments: what it reads is decided by the module’s saved settings, never by the caller, so a probe cannot be pointed at a host, a path or a login of the caller’s choosing.
The one thing a caller may add is module, which says whose saved settings
to use when more than one loaded module answers the probe - typically one
module loaded twice under two aliases, such as two CheckMSSQL with different
connections. It matches an instance from the listing first, then a module
name. Without it, the probe runs on the only module that answers it; when
several do, the agent refuses with 409 and lists them rather than pick one.
A body or any other query parameter is ignored.
| Key | Value |
|---|---|
| Verb | POST |
| Address | /api/v2/discovery/<probe> |
| Query | module (optional) |
| Privilege | discovery.run |
Request¶
POST /api/v2/discovery/pdh.counters
Response¶
{
"probe": "pdh.counters",
"module": "CheckSystem",
"instance": "CheckSystem",
"records": [
{ "id": "\\Memory\\Available Bytes", "object": "Memory", "counter": "Available Bytes" },
{ "id": "\\Processor\\% Processor Time", "object": "Processor", "counter": "% Processor Time" }
]
}
Every record has an id, which is what the rest of the agent calls the thing
(here, the counter path a check_pdh takes). A warning field appears when
the probe answered but had to drop something, such as a record without an id.
| Status | When |
|---|---|
| 200 | The probe answered. |
| 403 | The caller lacks discovery.run. |
| 404 | No loaded module answers a probe of that name (or, with module, that module does not). |
| 409 | Several loaded modules answer the probe and module did not pick one. The JSON body lists candidates. |
| 429 | The same probe is already running on that module for another caller. One run at a time; try again shortly. |
| 500 | The probe failed; the body says why. |
Example¶
curl -s -k -u admin -X POST https://localhost:8443/api/v2/discovery/pdh.counters | python -m json.tool
curl -s -k -u admin -X POST "https://localhost:8443/api/v2/discovery/mssql.databases?module=reporting"
A 409 names the modules to choose from:
{
"error": "Several modules answer the probe mssql.databases (CheckMSSQL, reporting): name the one to ask",
"probe": "mssql.databases",
"candidates": [
{ "module": "CheckMSSQL", "instance": "CheckMSSQL" },
{ "module": "CheckMSSQL", "instance": "reporting" }
]
}
Suggested modules¶
Which modules are worth enabling on this host, from what is installed and
running. The agent runs the two presence probes, host.services and
host.software, and matches them against a short list of things it
recognises, then adds the basic health modules every host wants. The web UI
shows the answer on the Suggestions page, where a suggested module can be
loaded and enabled with one click, and marks what was found Found on this
host in the module list.
| Key | Value |
|---|---|
| Verb | GET |
| Address | /api/v2/discovery/recommendations |
| Privilege | discovery.run |
Response¶
{
"recommendations": [
{
"module": "CheckMSSQL",
"loaded": false,
"enabled": false,
"commands": ["check_mssql", "check_mssql_databases", "check_mssql_backup", "check_mssql_jobs"],
"evidence": "The SQL Server service is running (service MSSQLSERVER).",
"baseline": false
},
{
"module": "CheckDisk",
"loaded": true,
"enabled": true,
"commands": ["check_drivesize"],
"evidence": "Free space on the drives: worth watching on every host.",
"baseline": true
}
],
"notes": [
"host.software: Probe failed: no supported package manager found"
]
}
| Field | Meaning |
|---|---|
module |
The module to enable. Only modules this installation can load are suggested. |
loaded |
The module is loaded already: accepting the suggestion means adding checks, not loading it. |
enabled |
The module is enabled in the configuration, so it is loaded when the agent starts. A module loaded by hand is loaded but not enabled, and is gone at the next restart. |
commands |
The checks in that module that apply. |
evidence |
Why, as a sentence to show the user. |
baseline |
Suggested for every host rather than for something found on this one. What was found comes first. |
notes |
One line per presence probe that could not be asked, and why. The other probe’s answer is still used, so a container without systemd still gets the suggestions its packages support. |
A running service is the strongest reason; a service in another or an unknown state (paused, starting - macOS reports none) is next, then installed software, and a service reported stopped is the weakest - still worth saying, since a stopped SQL Server is one an operator probably wants watched. On Linux the services include those installed but disabled and never started. The rules recognise:
| Module | Recognised by |
|---|---|
| CheckMSSQL | Services MSSQLSERVER, MSSQL$<instance>, mssql-server; package mssql-server |
| CheckMySQL | Services MySQL, MySQL5*, MySQL8*, MariaDB, mysql, mysqld, mariadb; packages mysql-server*, mariadb-server*, MySQL Server*, MariaDB 1*, MariaDB 2* (the version after the name keeps the MariaDB client libraries out) |
| CheckDocker | Services docker, com.docker.service; packages docker-ce, docker.io, docker-engine, moby-engine, Docker Desktop*, Rancher Desktop*, rancher-desktop |
| CheckWindowsApps | Service W3SVC (IIS). WAS alone is not enough: it is also installed for WCF activation without a web server |
| CheckHyperV | Service vmms |
Every host is also offered, as baseline, the modules this installation has
of CheckSystem (check_cpu, check_memory, check_uptime,
check_service), CheckDisk (check_drivesize) and CheckEventLog
(check_eventlog, Windows).
Names are compared without case; a trailing * matches any ending. Asking
runs both presence probes and reads the module list, so it costs what they
cost. On a Linux host that is the package query (dpkg-query, rpm or
pacman) plus three systemctl calls - the unit files, the loaded units, and
a show for every service in batches of 128 - which is well under a second
on a typical host. The web UI keeps the answer for five minutes.
curl -s -k -u admin https://localhost:8443/api/v2/discovery/recommendations | python -m json.tool
The same suggestions are available without the web server, from
the command line: nscp discovery --suggest prints
them and nscp discovery --enable-suggested enables them.
Probes¶
| Probe | Kind | Module | Answers | Record fields |
|---|---|---|---|---|
host.services |
presence | CheckSystem | The services on this host and whether they run: the service manager on Windows, systemd on Linux, launchd on macOS | display_name, start_type, state |
host.software |
presence | CheckSystem | The installed software by name: the uninstall registry on Windows, dpkg, rpm or pacman on Linux | version, publisher, source |
pdh.counters |
detail | CheckSystem (Windows) | Every counter of every PDH object, as \object\counter, without instances |
object, counter |
mssql.instances |
detail | CheckMSSQL (Windows) | The SQL Server instances installed on this machine, read from the registry; no login used. The id is the server to connect to: localhost or localhost\NAME |
instance, instance_id, version, edition |
mssql.databases |
detail | CheckMSSQL (Windows) | The databases the configured login sees on the configured server | recovery_model, collation, read_only, compatibility_level |
mysql.databases |
detail | CheckMySQL | The databases (schemas) the configured login sees on the configured server | character_set, collation |
scripts.external |
detail | CheckExternalScripts | The files under the configured script root | script, name |
scripts.python |
detail | PythonScript | The scripts under <script root>/python |
script, name |
scripts.lua |
detail | LUAScript | The scripts under <script root>/lua |
script, name |
The database probes use the connection saved under [/settings/mssql] or
[/settings/mysql] and nothing else; a probe takes no server or login of the
caller’s, so it cannot be pointed elsewhere. The script probes list the
configured script root and nothing above it: a record’s id is the path below
the root, script is the spelling a script or command setting takes, and
lib helper folders are left out as list leaves them out.
pdh.counters is slow the first time: the first listing after the agent
starts can take 30 seconds or more, because Windows loads every performance
counter provider on the first enumeration in a process. Later listings are
quicker. A client calling it should allow for that in its HTTP timeout, and a
second call made while the first is still running gets 429.
A probe name belongs to one module: the build refuses two modules declaring the same name, and when an out-of-tree module does it the agent logs a warning as the module is loaded.
The same probes are reachable from the nscp test console: discover lists
them, discover <probe> runs one and discover <probe> <module> runs it on
the named module.
From the command line¶
nscp discovery answers the same questions without the web server, a login
or a running service. It starts an agent for the one command, with the
modules the configuration enables, asks, and exits.
| Command | Does |
|---|---|
nscp discovery --list |
Lists the probes the loaded modules answer. |
nscp discovery --run <probe> |
Runs one probe and prints its records. Nothing is kept. |
nscp discovery --run <probe> --module <module> |
The same, on the named module (its alias, or its name) when several answer the probe. |
nscp discovery --suggest |
Shows the suggested modules, why, and whether each is enabled. |
nscp discovery --enable-suggested |
Enables every suggested module that is not enabled yet, and saves the configuration. |
--json prints what the REST API answers instead of text (a listed probe has
no url), for --list, --run and --suggest. The exit code is 0, or 1
when the command could not be answered. For --run that is a probe nothing
answers, one that failed, or one that several modules answer and no
--module picked; with --json the refusal goes to stderr, so stdout is
either the answer or empty. For --suggest and --enable-suggested it is
when neither presence probe could be asked, so nothing about the host was
looked at: the modules offered to every host are still shown, and enabled,
and the reasons are printed. One probe failing (a container without systemd)
is a note, not a failure. --enable-suggested also exits 1 when the
configuration could not be saved, and then reports nothing as enabled.
$ nscp discovery --suggest
Found on this host:
CheckDocker (not enabled)
The Docker service is running (service docker).
Checks: check_docker, check_docker_info, check_docker_stats
For every host:
CheckSystem (loaded, not enabled)
CPU, memory, uptime and services: worth watching on every host.
Checks: check_cpu, check_memory, check_uptime, check_service
CheckDisk (enabled)
Free space on the drives: worth watching on every host.
Checks: check_drivesize
Enable the ones not enabled yet with: nscp discovery --enable-suggested
$ nscp discovery --enable-suggested
CheckDisk: already enabled
CheckDocker: enabled. The Docker service is running (service docker).
CheckSystem: enabled. CPU, memory, uptime and services: worth watching on every host.
Enabled 2 modules. Restart the service for it to load them.
The suggestions are built from what CheckSystem’s two presence probes say,
so nscp discovery loads CheckSystem for the run when the configuration does
not enable it - a fresh install gets its suggestions without anything being
set up first. That changes nothing in the configuration: CheckSystem ends up
enabled only if --enable-suggested enables it, which it does, as one of the
modules every host is offered. --list shows its probes for the same reason.
CheckSystem (loaded, not enabled) in the sample is that: loaded for this
run, not enabled in the configuration.
--enable-suggested only adds: a module the configuration disables
explicitly (CheckSystem = disabled) is left as it is and reported as left
alone, and one enabled under an alias is not enabled a second time. It
writes <module> = enabled under [/modules] for each
module and nothing else: no module settings, and no checks are scheduled. A
running service does not notice; restart it to load the modules. It enables
both what was found on the host and the modules offered to every host. To
choose, read --suggest and enable the ones wanted with
nscp settings --activate-module <module> ....
The command runs as whoever starts it and reads the host directly, so it is
not behind discovery.run; it needs what reading and writing the
configuration needs, like nscp settings. A probe that reads with a stored
login (mssql.databases, mysql.databases) uses the saved settings, as it
does over REST.