Loading…
Loading…
Discover and synchronize Citrix NetScaler virtual servers and their backend members into the platform using the NITRO API. Learn how the discovery process
The Citrix Discovery Service automates the discovery of virtual servers from a Citrix NetScaler appliance using its NITRO REST API. The service connects to a target NetScaler instance, enumerates all configured load balancing virtual servers (lbvserver), resolves their backend service members, and synchronizes this data into the platform's database.
This component solves the problem of keeping the platform's service catalog up-to-date with the configuration of an external load balancer. It provides a mechanism to idempotently create, update, and deactivate service representations based on the live state of the NetScaler appliance.
The discovery process is initiated by an administrative action, which invokes the runDiscovery method with a target instance identifier. The service then:
s2r_discovered_service table within a single database transaction.DiscoveryResult object summarizing the outcome, including any non-fatal errors encountered.The discovery process follows a precise sequence of operations to ensure data consistency and provide detailed feedback. The entire persistence phase is transactional; either all database changes are committed, or none are.
flowchart TD
subgraph "Discovery Run"
A[Start] --> B(Load Credentials);
B --> C(Login to Citrix NITRO API);
C --> D(List Virtual Servers);
D --> E{For each server};
E -- Yes --> F(Get Backend Members);
F --> E;
E -- No --> G(Logout from NITRO API);
end
subgraph "Database Synchronization"
G --> H(Begin Transaction);
H --> I{For each discovered server};
I -- Yes --> J{Server exists in DB?};
J -- Yes --> K(Update Server Record);
J -- No --> L(Insert New Server Record);
K --> I;
L --> I;
I -- No --> M(Mark Unseen Servers as Inactive);
M --> N(Commit Transaction);
end
subgraph "Result"
N --> O(Return DiscoveryResult);
B -- Fail --> O;
C -- Fail --> O;
D -- Fail --> G;
N -- Fail --> P(Rollback & Return Error);
P --> O;
endgatewayType and instanceName from the LbConnectorCredentialService.GET /nitro/v1/config/lbvserver request to fetch all load balancing virtual servers.s2r_discovered_service database table in a single transaction.
gateway_type, instance_name, and vendor_service_id (the virtual server's name) already exists.last_seen_at timestamp is refreshed.is_active = false) if they were not found in the current discovery run. This prunes services that have been removed from the NetScaler appliance.
finally block.DiscoveryResult object is returned, containing counters for discovered, new, updated, and inactive services, along with a list of any non-fatal errors that occurred.The service exposes a single public method, runDiscovery, to initiate a discovery run.
runDiscovery MethodThis method executes a full discovery and synchronization pass for a specific Citrix NetScaler instance.
DiscoveryResult runDiscovery(String gatewayType, String instanceName)
| Name | Type | Required | Description |
|---|---|---|---|
gatewayType | String | Yes | The type of the gateway, used to look up credentials. For example, citrix-netscaler. |
instanceName | String | Yes | The unique name of the specific NetScaler instance to connect to. For example, ns-prod-01. |
Returns a DiscoveryResult object detailing the outcome of the run.
IMPORTANT
A successful HTTP response (e.g., HTTP 200) from the calling endpoint does not guarantee a fully successful discovery. The caller must inspect the errors list within the returned DiscoveryResult object to check for non-fatal issues that occurred during the process.
| Exception | Reason |
|---|---|
LbConnectorCredentialService.<br>NotFoundException | No credentials are registered for the given gatewayType and instanceName. |
DiscoveryResult ObjectThis object encapsulates the results of a discovery run.
| Field | Type | Description |
|---|---|---|
totalDiscovered | int | The total number of virtual servers enumerated from the NetScaler appliance. |
newlyAdded | int | The number of new records inserted into the s2r_discovered_service table. |
updated | int | The number of existing records that were updated with fresh data. |
markedInactive | int | The number of existing records that were marked as inactive because they were not found in this run. |
durationMs | long | The total wall-clock time for the discovery run, in milliseconds. |
errors | List<String> | A list of non-fatal error messages encountered during the run (e.g., failed lookups, session expiration). |
The primary side effect of the discovery service is the population of the s2r_discovered_service table. The service performs idempotent "upserts" to keep this table synchronized with the NetScaler appliance.
s2r_discovered_service Table Schema| Column | Type | Description |
|---|---|---|
gateway_type | String | The type of the gateway instance (e.g., citrix-netscaler). Part of the composite key. |
instance_name | String | The name of the specific gateway instance. Part of the composite key. |
vendor_service_id | String | The unique identifier of the service from the vendor's perspective (the name of the lbvserver). Part of the composite key. |
display_name | String | A user-friendly name for the service, which defaults to the vendor_service_id. |
frontend_host | String | The virtual IP address (ipv46) of the virtual server. |
frontend_port | Integer | The port number of the virtual server. |
frontend_protocol | String | The protocol or service type (e.g., HTTP, SSL, TCP). |
backend_pool_name | String | The name of the backend pool. For NetScaler, this defaults to the virtual server's name. |
backend_members | JSONB | A JSON array of objects representing the backend service members, including their name, host, port, and state. |
raw_metadata | JSONB | The complete, raw JSON object for the virtual server as returned by the NITRO API. |
discovered_at | Timestamp | The timestamp when the service was first discovered and inserted into the table. |
last_seen_at | Timestamp | The timestamp of the last discovery run in which this service was seen. |
is_active | Boolean | A flag indicating if the service was found in the most recent successful discovery run for this instance. |
The service is designed to be resilient, capturing errors without halting the entire process where possible. Errors are logged and returned in the errors list of the DiscoveryResult object.
| Error Code / Message | Trigger | Impact |
|---|---|---|
S2R-LBC-0502 failed to build NITRO client | An issue occurred while initializing the CitrixNitroClient, often due to invalid configuration. | The discovery run for the instance is aborted. The error is returned in the DiscoveryResult. |
S2R-LBC-0502 NITRO login failed | Invalid credentials (username/password), network connectivity issues, or firewall rules blocking access. | The discovery run for the instance is aborted. The error is returned in the DiscoveryResult. |
S2R-LBC-0502 NITRO session expired | The NITRO API session timed out during a long-running enumeration. | The run is partially successful. Any data discovered before the session expired is persisted. The error is returned in the DiscoveryResult. |
S2R-LBC-0502 NITRO enumeration error | A generic failure during an API call to list virtual servers (lbvserver). | The discovery run for the instance is aborted. The error is returned in the DiscoveryResult. |
S2R-LBC-0502 getLbVServerBindings(...) error | An error occurred while fetching the service bindings for a specific virtual server. | Discovery for that single virtual server is skipped. The run continues with other virtual servers. The error is added to the errors list. |
S2R-LBC-0502 getService(...) error | An error occurred while fetching the details (IP/port) for a specific backend service member. | The details for that single backend member are omitted. The run continues. The error is added to the errors list. |
S2R-LBC-0502 DB persist error | The database transaction to upsert discovered services failed. | No data from the discovery run is saved to the database due to the transaction rollback. The error is returned in the DiscoveryResult. |