Documentation ¶
Index ¶
Constants ¶
const ( // SnmpJobURI is the agent uri for snmp poll requests SnmpJobURI = "/r/poll" // CheckURI is the agent keep-alive uri CheckURI = "/r/check" // PingJobURI is the agent uri for ping jobs PingJobURI = "/r/ping" // OngoingURI is the agent current ongoing request list uri endpoint OngoingURI = "/r/ongoing" // ReportURI is the controller report callback uri ReportURI = "/r/report" )
const ( // Version1 is for snmp v1 Version1 = "1" // Version2c is for snmp v2c Version2c = "2c" // Version3 is for snmp v3 Version3 = "3" )
Variables ¶
var PostProcessorPat = regexp.MustCompile(`^parse-hex-[bl]e|parse-int|trim|(div|mul)[:-]\d+$`)
PostProcessorPat is a pattern listing all valid transformations available.
Functions ¶
func GroupByOid ¶
GroupByOid returns a list of an array of metrics grouped by base OID.
Types ¶
type Device ¶
type Device struct { // ID is the device id. ID int `db:"id" json:"id"` // Active tells whether the device can be polled. Active bool `db:"active" json:"active"` // Hostname is the device's FQDN. Hostname string `db:"hostname" json:"hostname"` // PollingFrequency is the device's snmp polling frequency. PollingFrequency int `db:"polling_frequency" json:"polling_frequency"` // PingFrequency is the device's ping frequency PingFrequency int `db:"ping_frequency" json:"ping_frequency"` // Tags is the influx tags (and prometheus labels) added to // each measurement of this device. Tags string `db:"tags" json:"tags,omitempty"` // SnmpParams is the device snmp config. SnmpParams // Profile is the device profile. Profile }
Device represents an snmp device.
func (*Device) UnmarshalJSON ¶
UnmarshalJSON implements the json Unmarshaler interface for Device type. Takes a flat json and builds a Device with embedded Profile and SnmpParams. Note: the standard Marshaler also outputs a flat json document.
type IndexedMeasure ¶
type IndexedMeasure struct { // ID is the measure db id. ID int `db:"id"` // Name is the name of the indexed measure. Name string `db:"name"` // Description is the description of the indexed measure. Description string `db:"description"` // Metrics is the list of metrics forming this measure. Metrics []Metric // IndexMetricID is the id of the metric used as index. IndexMetricID NullInt64 `db:"index_metric_id"` // IndexPos is the position of the index metric in the Metrics array. IndexPos int `db:"-"` // FilterPattern is the regex pattern used to filter the IndexedResults of this metric group. // It can be used to only keep results from interesting interfaces. FilterPattern string `db:"filter_pattern"` // FilterMetricID is the id of the metric on which the filter is applied. FilterMetricID NullInt64 `db:"filter_metric_id"` // FilterPos is the index of the filter metric in the Metrics array. FilterPos int `db:"-"` // InvertFilterMatch negates the match result of the FilterPattern. InvertFilterMatch bool `db:"invert_filter_match"` // FilterRegex is the compiled FilterPattern pattern. FilterRegex *regexp.Regexp `db:"-" json:"-"` // UseAlternateCommunity tells wether to use the alternate community for all metrics of this measure. UseAlternateCommunity bool `db:"use_alternate_community"` // ToKafka is a flag telling if the results should be exported to Kafka. ToKafka bool `db:"to_kafka"` // ToProm tells if the results are kept for Prometheus scraping. ToProm bool `db:"to_prometheus"` // ToInflux is a flag telling if the results should be exported to InfluxDB. ToInflux bool `db:"to_influx"` // LabelsOnly tell wehere this measure contains only labels. LabelsOnly bool `db:"-"` }
IndexedMeasure is a group of tabular metrics indexed by the first one.
func (*IndexedMeasure) RemoveInactive ¶
func (x *IndexedMeasure) RemoveInactive()
RemoveInactive filters out all metrics of this indexed measure that are marked as inactive.
func (*IndexedMeasure) UnmarshalJSON ¶
func (x *IndexedMeasure) UnmarshalJSON(data []byte) error
UnmarshalJSON unserializes data into an IndexedMetric. Checks specifically if the filter index and pattern are valid.
type Metric ¶
type Metric struct { // ID is the metric db ID. ID int `db:"id"` // Name is the metric name. Name string `db:"name"` // Oid is the metric OID. Oid OID `db:"oid"` // Description is the metric description. Description string `db:"description"` // PollingFrequency is the metric polling frequency. // Must be a multiple of the device polling frequency. PollingFrequency int `db:"polling_frequency"` // LastPolledAt is the metric's last poll time (on this device). LastPolledAt NullTime `db:"last_polled_at"` // Active indicates if this metric is actually polled (all inactive metrics are ignored). Active bool `db:"active"` // ExportAsLabel tells if this metric is exported as a prometheus label (instead of value). ExportAsLabel bool `db:"export_as_label"` // ExportedName is the name to use for the exported metric (different from the metric name). ExportedName string `db:"exported_name"` // PostProcessors is a list of post transformations to apply to metric result. PostProcessors pq.StringArray `db:"post_processors"` // IndexPattern is the regex with subexpression used to extract index from tabular Oids. IndexPattern string `json:",omitempty" db:"index_pattern"` // IndexRegex is the compiled IndexPattern regexp. IndexRegex *regexp.Regexp `json:"-" db:"-"` }
Metric represents a single snmp OID to poll.
func (*Metric) UnmarshalJSON ¶
UnmarshalJSON unserializes a Metric. Checks specifically if the index pattern is valid and contains at least one sub-expression.
type NullInt64 ¶
NullInt64 is a sql.NullInt64 with custom json marshaller/unmarshaller.
func (NullInt64) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface with invalid values converted to json `null`.
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface with a special case for json `null` (unquoted) converted as a null int without error.
type NullTime ¶
NullTime represents a nullable time.Time.
func (NullTime) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. Accepts either `null` (unquoted) or a quoted string in RFC 3339 format.
type OID ¶
type OID string
OID represents a dotted OID string.
func (OID) CacheKey ¶
CacheKey computes the key used to cache metric result depending on the community used.
func (OID) MarshalJSON ¶
MarshalJSON implements the json Marshaler interface for the OID.
func (*OID) UnmarshalJSON ¶
UnmarshalJSON implements the json Unmarshaler interface for the OID Validates the correct oid format and adds leading dot if needed.
type OngoingPolls ¶
type OngoingPolls struct { // Requests is the current polling requests IDs. Requests []string `json:"ongoing"` // Load is the current load of the agent. Load float64 `json:"load"` }
OngoingPolls is the result to the OngoingURI api request.
type PingHost ¶
type PingHost struct { // ID is the target db id ID int `db:"id" json:"id"` // Name is the target hostname Name string `db:"hostname" json:"hostname"` // IPAddr is the target ip address IPAddr string `db:"ip_address" json:"ip_address"` // Category is the equipment category (for profile identification) Category string `db:"category" json:"category"` // Vendor is the equipment vendor (for profile identification) Vendor string `db:"vendor" json:"vendor"` // Model is the equipment model (for profile identification) Model string `db:"model" json:"model"` }
PingHost is a host to ping.
type PingRequest ¶
type PingRequest struct { // UID is the request unique ID UID string `json:"uid"` // Hosts is the list of hosts to ping Hosts []PingHost `json:"hosts"` // Stamp is the ping metric timestamp Stamp time.Time `json:"-"` }
PingRequest is a ping job sent to an agent.
func (PingRequest) HostIDs ¶
func (r PingRequest) HostIDs() []int
HostIDs returns the list of host IDs of this ping request.
func (PingRequest) Targets ¶
func (r PingRequest) Targets() []string
Targets returns the list of host IPs of this ping request.
type Profile ¶
type Profile struct { // ID is the device profile id. ID int `db:"profile_id" json:"-"` // Category is the device category (router, switch, dslam, etc.) Category string `db:"category" json:"category"` // Vendor is the device vendor. Vendor string `db:"vendor" json:"vendor"` // Model is the device model. Model string `db:"model" json:"model"` }
Profile represents the device profile. A profile is composed of a unique (model, vendor, category) tuple and have a list of scalar and tabular measures attached to it.
func (*Profile) UnmarshalJSON ¶
UnmarshalJSON implements json Unmarhsaler interface for a Profile. Validates that the Category, Vendor and Model fields are not empty.
type ScalarMeasure ¶
type ScalarMeasure struct { // ID is the measure id ID int `db:"id"` // Name is the name of the scalar measure Name string `db:"name"` // Description is the description of the scalar metric Description string `db:"description"` // Metrics is the list of metrics of this scalar measure Metrics []Metric // UseAlternateCommunity tells wether to use the alternate community for all metrics of this measure. UseAlternateCommunity bool `db:"use_alternate_community"` // ToKafka is a flag telling if the results should be exported to Kafka. ToKafka bool `db:"to_kafka"` // ToProm tells if the results are kept for Prometheus scraping. ToProm bool `db:"to_prometheus"` // ToInflux is a flag telling if the results should be exported to InfluxDB. ToInflux bool `db:"to_influx"` }
ScalarMeasure is a scalar measure with its list of scalar metrics like sysInfo, sysUsage...
func (*ScalarMeasure) RemoveInactive ¶
func (scalar *ScalarMeasure) RemoveInactive()
RemoveInactive filters out all metrics of this scalar measure marked as inactive.
type SnmpParams ¶
type SnmpParams struct { // IPAddress is the device's ip address for snmp polling. IPAddress string `db:"ip_address" json:"ip_address"` // Port is the device's snmp port. Port int `db:"snmp_port" json:"snmp_port"` // Version is the snmp version available for the device. Version string `db:"snmp_version" json:"snmp_version"` // Community is the device's snmp community. Community string `db:"snmp_community" json:"snmp_community"` // AlternateCommunity is an alternate snmp community used for querying some metrics. AlternateCommunity string `db:"snmp_alternate_community" json:"snmp_alternate_community"` // Timeout is the snmp query timeout (default 10s). Timeout int `db:"snmp_timeout" json:"snmp_timeout"` // Retries is the number of retries to attempt on timeout (default 1). Retries int `db:"snmp_retries" json:"snmp_retries"` // DisableBulk is a flag that disables snmp bulk requests (automatic for snmp v1). DisableBulk bool `db:"snmp_disable_bulk" json:"snmp_disable_bulk,omitempty"` // ConnectionCount is the number of possible simultaneous snmp queries // to the device (defaults to 1). ConnectionCount int `db:"snmp_connection_count" json:"snmp_connection_count"` // SecLevel is the security level for snmpv3: "NoAuthNoPriv", "AuthNoPriv" or "AuthPriv". SecLevel string `db:"snmpv3_security_level" json:"snmpv3_security_level,omitempty"` // AuthUser is the authentication username for snmpv3. AuthUser string `db:"snmpv3_auth_user" json:"snmpv3_auth_user,omitempty"` // AuthProto is the authentication protocol for snmpv3: "MD5" or "SHA". AuthProto string `db:"snmpv3_auth_proto" json:"snmpv3_auth_proto,omitempty"` // AuthPasswd is the authentication password for snmpv3. AuthPasswd string `db:"snmpv3_auth_passwd" json:"snmpv3_auth_passwd,omitempty"` // PrivProto is the privacy protocol for snmpv3: "DES" or "AES". PrivProto string `db:"snmpv3_privacy_proto" json:"snmpv3_privacy_proto,omitempty"` // PrivPasswd is the privacy passphrase for snmpv3. PrivPasswd string `db:"snmpv3_privacy_passwd" json:"snmpv3_privacy_passwd,omitempty"` }
SnmpParams represents the snmp config params.
func (SnmpParams) GoSnmpVersion ¶
func (s SnmpParams) GoSnmpVersion() gosnmp.SnmpVersion
GoSnmpVersion converts the snmp version to a gosnmp version.
func (*SnmpParams) UnmarshalJSON ¶
func (s *SnmpParams) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json Unmarshaler interface. Does some additional checks and sets default values for fields.
type SnmpRequest ¶
type SnmpRequest struct { // UID is the request unique id UID string `json:"uid"` // AgentID is the agent id AgentID int `json:"agent_id"` // ScalarMeasures is a list of scalar measures to poll ScalarMeasures []ScalarMeasure `json:",omitempty"` // IndexedMeasures is a list of tabular measures to poll IndexedMeasures []IndexedMeasure `json:",omitempty"` // ReportURL is the url where the polling result report is sent ReportURL string `json:"report_url"` // Device is the network device to poll. Device Device `json:"device"` }
SnmpRequest represents a snmp poll request.
func (*SnmpRequest) UnmarshalJSON ¶
func (r *SnmpRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON validates the json input and unmarshals it to and SnmpRequest.