Add first version of VES agent and vesmgr
[ric-plt/vespamgr.git] / cmd / vesmgr / config.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         "gopkg.in/yaml.v2"
22         "time"
23         "io"
24 )
25
26 func basicVespaConf() VESAgentConfiguration {
27         var vespaconf = VESAgentConfiguration {
28                 DataDir: "/tmp/data",
29                 Debug:   false,
30                 PrimaryCollector: CollectorConfiguration {
31                         User: "user",
32                         Password: "pass",
33                         PassPhrase: "pass",
34                 },
35                 Event: EventConfiguration {
36                         VNFName: "vespa-demo", // XXX
37                         ReportingEntityID: "1af5bfa9-40b4-4522-b045-40e54f0310f", // XXX
38                         MaxSize: 2000000,
39                         NfNamingCode: "hsxp",
40                         NfcNamingCodes: [] NfcNamingCode {
41                                 NfcNamingCode {
42                                         Type: "oam",
43                                         Vnfcs: [] string {"lr-ope-0","lr-ope-1","lr-ope-2"},
44                                 },
45                                 NfcNamingCode {
46                                         Type: "etl",
47                                         Vnfcs: [] string {"lr-pro-0","lr-pro-1"},
48                                 },
49                         },
50                         RetryInterval: time.Second * 5,
51                         MaxMissed: 2,
52                 },
53                 Measurement: MeasurementConfiguration {
54                         DomainAbbreviation: "Mvfs",
55                         MaxBufferingDuration: time.Hour,
56                         Prometheus: PrometheusConfig {
57                                 Timeout: time.Second * 30,
58                                 KeepAlive: time.Second * 30,
59                                 Rules: MetricRules {
60                                         DefaultValues: &MetricRule {
61                                                 VMIDLabel: "'{{.labels.instance}}'",
62                                         },
63                                 },
64                         },
65                 },
66         }
67         return vespaconf
68 }
69
70 func getRules(vespaconf *VESAgentConfiguration) {
71         // XXX
72         makeRule := func(expr string, obj_name string, obj_instance string) MetricRule {
73                 return MetricRule {
74                         Target: "AdditionalObject",
75                         Expr: expr,
76                         ObjectInstance: obj_instance,
77                         ObjectName: obj_name,
78                         ObjectKeys: [] Label {
79                                 Label {
80                                         Name: "ricComponentName",
81                                         Expr: "'{{.labels.app_kubernetes_io_instance}}'",
82                                 },
83                         },
84                 }
85         }
86         // Hard coded for now
87         vespaconf.Measurement.Prometheus.Rules.Metrics = []MetricRule {
88                 makeRule("ricxapp_RMR_Received", "ricxappRMRreceivedCounter", "ricxappRMRReceived"),
89                 makeRule("ricxapp_RMR_ReceiveError", "ricxappRMRReceiveErrorCounter", "ricxappRMRReceiveError"),
90                 makeRule("ricxapp_RMR_Transmitted", "ricxappRMRTransmittedCounter", "ricxappRMRTransmitted"),
91                 makeRule("ricxapp_RMR_TransmitError", "ricxappRMRTransmitErrorCounter", "ricxappRMRTransmitError"),
92                 makeRule("ricxapp_SDL_Stored", "ricxappSDLStoredCounter", "ricxappSDLStored"),
93                 makeRule("ricxapp_SDL_StoreError", "ricxappSDLStoreErrorCounter", "ricxappSDLStoreError"),
94         }
95
96 }
97
98 func createVespaConfig(writer io.Writer) {
99         vespaconf := basicVespaConf()
100         getRules(&vespaconf)
101         err := yaml.NewEncoder(writer).Encode(vespaconf)
102         if err != nil {
103                 logger.Error("Cannot write vespa conf file: %s", err.Error())
104                 return
105         }
106 }