Class Agent
Namespace: Consul
Assembly: Consul.dll
Agent can be used to query the Agent endpoints
public class Agent : IAgentEndpoint
Inheritance
Implements
Inherited Members
object.Equals(object) , object.Equals(object, object) , object.GetHashCode() , object.GetType() , object.MemberwiseClone() , object.ReferenceEquals(object, object) , object.ToString()
Properties
NodeName
NodeName is used to get the node name of the agent
[Obsolete("This property will be removed in a future version. Replace uses of it with a call to 'await GetNodeName()'")]
public string NodeName { get; }
Property Value
Methods
CheckDeregister(string, CancellationToken)
CheckDeregister is used to deregister a check with the local agent
public Task<WriteResult> CheckDeregister(string checkID, CancellationToken ct = default)
Parameters
checkID
string
The check ID to deregister
The cancellation token
Returns
Task <WriteResult >
An empty write result
CheckRegister(AgentCheckRegistration, CancellationToken)
CheckRegister is used to register a new check with the local agent
public Task<WriteResult> CheckRegister(AgentCheckRegistration check, CancellationToken ct = default)
Parameters
check
AgentCheckRegistration
A check registration object
The cancellation token
Returns
Task <WriteResult >
An empty write result
Checks(CancellationToken)
Checks returns the locally registered checks
public Task<QueryResult<Dictionary<string, AgentCheck>>> Checks(CancellationToken ct = default)
Parameters
Returns
Task <QueryResult <Dictionary <string , AgentCheck >>>
A map of the registered check names and check data
Checks(Filter, CancellationToken)
Checks returns the locally registered checks
public Task<QueryResult<Dictionary<string, AgentCheck>>> Checks(Filter filter, CancellationToken ct = default)
Parameters
filter
Filter
Specifies the expression used to filter the queries results prior to returning the data
The cancellation token
Returns
Task <QueryResult <Dictionary <string , AgentCheck >>>
A map of the registered check names and check data
ConnectAuthorize(AgentAuthorizeParameters, CancellationToken)
ConnectAuthorize tests whether a connection is authorized between two services
public Task<WriteResult<AgentAuthorizeResponse>> ConnectAuthorize(AgentAuthorizeParameters parameters, CancellationToken ct = default)
Parameters
parameters
AgentAuthorizeParameters
Parameters for the request
Cancellation Token
Returns
Task <WriteResult <AgentAuthorizeResponse >>
An Authorize Response
ConnectAuthorize(AgentAuthorizeParameters, WriteOptions, CancellationToken)
ConnectAuthorize tests whether a connection is authorized between two services
public Task<WriteResult<AgentAuthorizeResponse>> ConnectAuthorize(AgentAuthorizeParameters parameters, WriteOptions w, CancellationToken ct = default)
Parameters
parameters
AgentAuthorizeParameters
Parameters for the request
Write Options
Cancellation Token
Returns
Task <WriteResult <AgentAuthorizeResponse >>
An Authorize Response
DisableNodeMaintenance(CancellationToken)
DisableNodeMaintenance toggles node maintenance mode off for the agent we are connected to
public Task<WriteResult> DisableNodeMaintenance(CancellationToken ct = default)
Parameters
Returns
Task <WriteResult >
An empty write result
DisableServiceMaintenance(string, CancellationToken)
DisableServiceMaintenance toggles service maintenance mode off for the given service ID
public Task<WriteResult> DisableServiceMaintenance(string serviceID, CancellationToken ct = default)
Parameters
serviceID
string
The service ID
The cancellation token
Returns
Task <WriteResult >
An empty write result
EnableNodeMaintenance(string, CancellationToken)
EnableNodeMaintenance toggles node maintenance mode on for the agent we are connected to
public Task<WriteResult> EnableNodeMaintenance(string reason, CancellationToken ct = default)
Parameters
reason
string
An optional reason
The cancellation token
Returns
Task <WriteResult >
An empty write result
EnableServiceMaintenance(string, string, CancellationToken)
EnableServiceMaintenance toggles service maintenance mode on for the given service ID
public Task<WriteResult> EnableServiceMaintenance(string serviceID, string reason, CancellationToken ct = default)
Parameters
serviceID
string
The service ID
reason
string
An optional reason
The cancellation token
Returns
Task <WriteResult >
An empty write result
FailTTL(string, string, CancellationToken)
FailTTL is used to set a TTL check to the failing state
public Task FailTTL(string checkID, string note, CancellationToken ct = default)
Parameters
checkID
string
The check ID
note
string
An optional, arbitrary string to write to the check status
The cancellation token
Returns
ForceLeave(string, CancellationToken)
ForceLeave is used to have the agent eject a failed node
public Task<WriteResult> ForceLeave(string node, CancellationToken ct = default)
Parameters
node
string
The node name to remove
The cancellation token
Returns
Task <WriteResult >
An empty write result
GetAgentHostInfo(CancellationToken)
GetAgentHostInfo returns the host info of the agent
public Task<QueryResult<AgentHostInfo>> GetAgentHostInfo(CancellationToken ct = default)
Parameters
The cancellation token
Returns
Task <QueryResult <AgentHostInfo >>
Agent Host Information
GetAgentMetrics(CancellationToken)
GetAgentMetrics returns the metrics of the local agent
public Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default)
Parameters
The cancellation token
Returns
Task <QueryResult <Metrics >>
Metrics of the local agent
GetAgentVersion(CancellationToken)
GetAgentVersion returns the version of the agent
public Task<QueryResult<AgentVersion>> GetAgentVersion(CancellationToken ct = default)
Parameters
The cancellation token
Returns
Task <QueryResult <AgentVersion >>
Version of the agent
GetCALeaf(string, CancellationToken)
GetCALeaf, returns the leaf certificate representing a single service
public Task<QueryResult<CALeaf>> GetCALeaf(string serviceId, CancellationToken ct = default)
Parameters
serviceId
string
Id of service to fetch
Cancellation Token
Returns
Task <QueryResult <CALeaf >>
Leaf certificate
GetCALeaf(string, QueryOptions, CancellationToken)
GetCALeaf, returns the leaf certificate representing a single service
public Task<QueryResult<CALeaf>> GetCALeaf(string serviceId, QueryOptions q, CancellationToken ct = default)
Parameters
serviceId
string
Id of service to fetch
Query Options
Cancellation Token
Returns
Task <QueryResult <CALeaf >>
Leaf certificate
GetCARoots(CancellationToken)
GetCARoots returns root certificates in the cluster
public Task<QueryResult<CARoots>> GetCARoots(CancellationToken ct = default)
Parameters
Cancellation Token
Returns
Task <QueryResult <CARoots >>
Root certificates
GetCARoots(QueryOptions, CancellationToken)
GetCARoots returns root certificates in the cluster
public Task<QueryResult<CARoots>> GetCARoots(QueryOptions q, CancellationToken ct = default)
Parameters
Query Options
Cancellation Token
Returns
Task <QueryResult <CARoots >>
Root certificates
GetLocalServiceHealth(string, QueryOptions, CancellationToken)
GetLocalServiceHealth returns the health info of a service registered on the local agent
public Task<QueryResult<LocalServiceHealth[]>> GetLocalServiceHealth(string serviceName, QueryOptions q, CancellationToken ct = default)
Parameters
serviceName
string
Name of service
The cancellation token
Returns
Task <QueryResult <LocalServiceHealth []>>
An array containing the details of each passing, warning, or critical service
GetLocalServiceHealth(string, CancellationToken)
GetLocalServiceHealth returns the health info of a service registered on the local agent
public Task<QueryResult<LocalServiceHealth[]>> GetLocalServiceHealth(string serviceName, CancellationToken ct = default)
Parameters
serviceName
string
Name of service
The cancellation token
Returns
Task <QueryResult <LocalServiceHealth []>>
An array containing the details of each passing, warning, or critical service
GetLocalServiceHealthByID(string, QueryOptions, CancellationToken)
GetLocalServiceHealthByID returns the health info of a service registered on the local agent by ID
public Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default)
Parameters
serviceID
string
ID of the service
The cancellation token
Returns
Task <QueryResult <LocalServiceHealth >>
An array containing the details of each passing, warning, or critical service
GetLocalServiceHealthByID(string, CancellationToken)
GetLocalServiceHealthByID returns the health info of a service registered on the local agent by ID
public Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default)
Parameters
serviceID
string
ID of the service
The cancellation token
Returns
Task <QueryResult <LocalServiceHealth >>
An array containing the details of each passing, warning, or critical service
GetNodeName(CancellationToken)
GetNodeName is used to get the node name of the agent. The value is cached per instance of ConsulClient after the first use.
public Task<string> GetNodeName(CancellationToken ct = default)
Parameters
Returns
GetServiceConfiguration(string, CancellationToken)
GetServiceConfiguration returns the service definition of a service registered on the local agent
public Task<QueryResult<ServiceConfiguration>> GetServiceConfiguration(string serviceId, CancellationToken ct = default)
Parameters
serviceId
string
Id of service to fetch
Cancellation Token
Returns
Task <QueryResult <ServiceConfiguration >>
Service Configuration
GetServiceConfiguration(string, QueryOptions, CancellationToken)
GetServiceConfiguration returns the service definition of a service registered on the local agent
public Task<QueryResult<ServiceConfiguration>> GetServiceConfiguration(string serviceId, QueryOptions q, CancellationToken ct = default)
Parameters
serviceId
string
Id of service to fetch
Query Options
Cancellation Token
Returns
Task <QueryResult <ServiceConfiguration >>
Service Configuration
GetWorstLocalServiceHealth(string, QueryOptions, CancellationToken)
GetWorstLocalServiceHealth returns the worst aggregated status of a service registered on the local agent
public Task<QueryResult<string>> GetWorstLocalServiceHealth(string serviceName, QueryOptions q, CancellationToken ct = default)
Parameters
serviceName
string
Name of service
The cancellation token
Returns
Task <QueryResult <string >>
passing, warning, or critical
GetWorstLocalServiceHealth(string, CancellationToken)
GetWorstLocalServiceHealth returns the worst aggregated status of a service registered on the local agent
public Task<QueryResult<string>> GetWorstLocalServiceHealth(string serviceName, CancellationToken ct = default)
Parameters
serviceName
string
Name of service
The cancellation token
Returns
Task <QueryResult <string >>
passing, warning, or critical
Join(string, bool, CancellationToken)
Join is used to instruct the agent to attempt a join to another cluster member
public Task<WriteResult> Join(string addr, bool wan, CancellationToken ct = default)
Parameters
addr
string
The address to join to
wan
bool
Join the WAN pool
The cancellation token
Returns
Task <WriteResult >
An empty write result
Leave(string, CancellationToken)
Leave is used to have the agent gracefully leave the cluster and shutdown
public Task<WriteResult> Leave(string node, CancellationToken ct = default)
Parameters
node
string
Returns
Task <WriteResult >
An empty write result
Members(bool, CancellationToken)
Members returns the known gossip members. The WAN flag can be used to query a server for WAN members.
public Task<QueryResult<AgentMember[]>> Members(bool wan, CancellationToken ct = default)
Parameters
wan
bool
Returns
Task <QueryResult <AgentMember []>>
An array of gossip peers
Monitor(LogLevel, CancellationToken)
Monitor yields log lines to display streaming logs from the agent Providing a CancellationToken can be used to close the connection and stop the log stream, otherwise the log stream will time out based on the HTTP Client's timeout value.
public Task<Agent.LogStream> Monitor(LogLevel level = LogLevel.Info, CancellationToken ct = default)
Parameters
level
LogLevel
Returns
MonitorJSON(LogLevel, CancellationToken)
MonitorJSON is like Monitor except it returns logs in JSON format.
public Task<Agent.LogStream> MonitorJSON(LogLevel level = LogLevel.Info, CancellationToken ct = default)
Parameters
level
LogLevel
Returns
PassTTL(string, string, CancellationToken)
PassTTL is used to set a TTL check to the passing state
public Task PassTTL(string checkID, string note, CancellationToken ct = default)
Parameters
checkID
string
The check ID
note
string
An optional, arbitrary string to write to the check status
The cancellation token
Returns
Reload(CancellationToken)
Reload triggers a configuration reload for the agent we are connected to.
public Task<WriteResult> Reload(CancellationToken ct = default)
Parameters
Returns
Task <WriteResult >
An empty write result
Reload(string, CancellationToken)
Reload triggers a configuration reload for the agent we are connected to.
[Obsolete]
public Task<WriteResult> Reload(string node, CancellationToken ct = default)
Parameters
node
string
The node name to reload
The cancellation token
Returns
Task <WriteResult >
An empty write result
Self(CancellationToken)
Self is used to query the agent we are speaking to for information about itself
public Task<QueryResult<Dictionary<string, Dictionary<string, dynamic>>>> Self(CancellationToken ct = default)
Parameters
Returns
Task <QueryResult <Dictionary <string , Dictionary <string , dynamic>>>>
A somewhat dynamic object representing the various data elements in Self
ServiceDeregister(string, CancellationToken)
ServiceRegister is used to register a new service with the local agent
public Task<WriteResult> ServiceDeregister(string serviceID, CancellationToken ct = default)
Parameters
serviceID
string
The service ID
The cancellation token
Returns
Task <WriteResult >
An empty write result
ServiceRegister(AgentServiceRegistration, CancellationToken)
ServiceRegister is used to register a new service with the local agent
public Task<WriteResult> ServiceRegister(AgentServiceRegistration service, CancellationToken ct = default)
Parameters
service
AgentServiceRegistration
A service registration object
The cancellation token
Returns
Task <WriteResult >
An empty write result
ServiceRegister(AgentServiceRegistration, bool, CancellationToken)
ServiceRegister is used to register a new service with the local agent
public Task<WriteResult> ServiceRegister(AgentServiceRegistration service, bool replaceExistingChecks, CancellationToken ct = default)
Parameters
service
AgentServiceRegistration
A service registration object
replaceExistingChecks
bool
Missing health checks from the request will be deleted from the agent.
The cancellation token
Returns
Task <WriteResult >
An empty write result
Services(CancellationToken)
Services returns the locally registered services
public Task<QueryResult<Dictionary<string, AgentService>>> Services(CancellationToken ct = default)
Parameters
Returns
Task <QueryResult <Dictionary <string , AgentService >>>
A map of the registered services and service data
Services(Filter, CancellationToken)
Services returns the locally registered services
public Task<QueryResult<Dictionary<string, AgentService>>> Services(Filter filter, CancellationToken ct = default)
Parameters
filter
Filter
Specifies the expression used to filter the queries results prior to returning the data
The cancellation token
Returns
Task <QueryResult <Dictionary <string , AgentService >>>
A map of the registered services and service data
UpdateTTL(string, string, TTLStatus, CancellationToken)
UpdateTTL is used to update the TTL of a check
public Task<WriteResult> UpdateTTL(string checkID, string output, TTLStatus status, CancellationToken ct = default)
Parameters
checkID
string
The check ID
output
string
An optional, arbitrary string to write to the check status
status
TTLStatus
The state to set the check to
The cancellation token
Returns
Task <WriteResult >
An empty write result
WarnTTL(string, string, CancellationToken)
WarnTTL is used to set a TTL check to the warning state
public Task WarnTTL(string checkID, string note, CancellationToken ct = default)
Parameters
checkID
string
The check ID
note
string
An optional, arbitrary string to write to the check status
The cancellation token