Add first version of VES agent and vesmgr
[ric-plt/vespamgr.git] / cmd / vesmgr / vespaconf.go
1 /*
2  *  Copyright (c) 2019 AT&T Intellectual Property.
3  *  Copyright (c) 2018-2019 Nokia.
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 package main
19
20 import (
21         "time"
22 )
23
24 // Structs are copied from https://github.com/nokia/ONAP-VESPA/tree/master/ves-agent/config
25 // and from https://github.com/nokia/ONAP-VESPA/blob/master/govel/config.go
26 // Using tag v0.3.0
27
28 // HeartbeatConfiguration parameters
29 type HeartbeatConfiguration struct {
30         DefaultInterval time.Duration `yaml:"defaultInterval"`
31 }
32
33 // Label represents a VES field by it's name, with an expression
34 // for getting its value
35 type Label struct {
36         Name string `yaml:"name"`
37         Expr string `yaml:"expr"`
38 }
39
40 // MetricRule defines how to retrieve metrics and map them
41 // into a list of evel.EventMeasurement struct
42 type MetricRule struct {
43         Target         string  `yaml:"target"`          // Target VES event field
44         Expr           string  `yaml:"expr"`            // Prometheus query expression
45         VMIDLabel      string  `yaml:"vmId"`            // Metric label holding the VNF ID
46         Labels         []Label `yaml:"labels"`          // Set of VES fields to map to values of given label
47         ObjectName     string  `yaml:"object_name"`     // JSON Object Name
48         ObjectInstance string  `yaml:"object_instance"` // JSON Object instance
49         ObjectKeys     []Label `yaml:"object_keys"`     // JSON Object keys
50 }
51
52 // MetricRules defines a list of rules, and defaults values for them
53 type MetricRules struct {
54         DefaultValues *MetricRule  `yaml:"defaults"` // Default rules to apply (except for expr), labels are merged
55         Metrics       []MetricRule `yaml:"metrics"`  // List of query and mapping of rules
56 }
57
58 // PrometheusConfig parameters
59 type PrometheusConfig struct {
60         Address   string        `yaml:"address"`   // Base URL to prometheus API
61         Timeout   time.Duration `yaml:"timeout"`   // API request timeout
62         KeepAlive time.Duration `yaml:"keepalive"` // HTTP Keep-Alive
63         Rules     MetricRules   `yaml:"rules"`     // Querying rules
64 }
65
66 // MeasurementConfiguration parameters
67 type MeasurementConfiguration struct {
68         DomainAbbreviation   string           `yaml:"domainAbbreviation"`   // "Measurement" or "Mfvs"
69         DefaultInterval      time.Duration    `yaml:"defaultInterval"`      // Default measurement interval
70         MaxBufferingDuration time.Duration    `yaml:"maxBufferingDuration"` // Maximum timeframe size of buffering
71         Prometheus           PrometheusConfig `yaml:"prometheus"`           // Prometheus configuration
72 }
73
74 // CollectorConfiguration parameters
75 type CollectorConfiguration struct {
76         ServerRoot string `yaml:"serverRoot"`
77         FQDN       string `yaml:"fqdn"`
78         Port       int    `yaml:"port"`
79         Secure     bool   `yaml:"secure"`
80         Topic      string `yaml:"topic"`
81         User       string `yaml:"user"`
82         Password   string `yaml:"password"`
83         PassPhrase string `yaml:"passphrase,omitempty"` // passPhrase used to encrypt collector password in file
84 }
85
86 //NfcNamingCode mapping bettween NfcNamingCode (oam or etl) and Vnfcs
87 type NfcNamingCode struct {
88         Type  string   `yaml:"type"`
89         Vnfcs []string `yaml:"vnfcs"`
90 }
91
92 // EventConfiguration parameters
93 type EventConfiguration struct {
94         VNFName             string          `yaml:"vnfName"`             // Name of this VNF, eg: dpa2bhsxp5001v
95         ReportingEntityName string          `yaml:"reportingEntityName"` // Value of reporting entity field. Usually local VM (VNFC) name
96         ReportingEntityID   string          `yaml:"reportingEntityID"`   // Value of reporting entity UUID. Usually local VM (VNFC) UUID
97         MaxSize             int             `yaml:"maxSize"`
98         NfNamingCode        string          `yaml:"nfNamingCode,omitempty"` // "hspx"
99         NfcNamingCodes      []NfcNamingCode `yaml:"nfcNamingCodes,omitempty"`
100         RetryInterval       time.Duration   `yaml:"retryInterval,omitempty"`
101         MaxMissed           int             `yaml:"maxMissed,omitempty"`
102 }
103
104 // VESAgentConfiguration parameters
105 type VESAgentConfiguration struct {
106         PrimaryCollector CollectorConfiguration   `yaml:"primaryCollector"`
107         Heartbeat        HeartbeatConfiguration   `yaml:"heartbeat,omitempty"`
108         Measurement      MeasurementConfiguration `yaml:"measurement,omitempty"`
109         Event            EventConfiguration       `yaml:"event,omitempty"`
110         Debug            bool                     `yaml:"debug,omitempty"`
111         CaCert           string                   `yaml:"caCert,omitempty"` // Root certificate content
112         DataDir          string                   `yaml:"datadir"`          // Path to directory containing data
113 }