1 /*
2   Copyright 2021 Northern.tech AS
3 
4   This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by the
8   Free Software Foundation; version 3.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
18 
19   To the extent this program is licensed as part of the Enterprise
20   versions of CFEngine, the applicable Commercial Open Source License
21   (COSL) may apply to this file if you as a licensee so wish it. See
22   included file COSL.txt.
23 */
24 
25 
26 #include <probes.h>
27 
28 
29 /* Structs */
30 
31 typedef struct
32 {
33     const char *name;
34     ProbeInit init;
35 } Probe;
36 
37 /* Constants */
38 
39 static const Probe ENTERPRISE_PROBES[] =
40 {
41     {"Input/output", &MonIoInit},
42     {"Memory", &MonMemoryInit},
43 };
44 
45 /* Globals */
46 
47 static ProbeGatherData ENTERPRISE_PROBES_GATHERERS[sizeof(ENTERPRISE_PROBES) / sizeof(ENTERPRISE_PROBES[0])];
48 
49 
MonOtherInit()50 void MonOtherInit()
51 {
52     Log(LOG_LEVEL_VERBOSE, "Starting initialization of static Nova monitoring probes.");
53 
54     for (size_t i = 0; i < sizeof(ENTERPRISE_PROBES) / sizeof(ENTERPRISE_PROBES[0]); ++i)
55     {
56         const Probe *probe = &ENTERPRISE_PROBES[i];
57         const char *provider;
58         const char *error;
59 
60         if ((ENTERPRISE_PROBES_GATHERERS[i] = (probe->init) (&provider, &error)))
61         {
62             Log(LOG_LEVEL_VERBOSE, " * %s: %s.", probe->name, provider);
63         }
64         else
65         {
66             Log(LOG_LEVEL_VERBOSE, " * %s: Disabled: %s.", probe->name, error);
67         }
68     }
69 
70     Log(LOG_LEVEL_VERBOSE, "Initialization of static Nova monitoring probes is finished.");
71 }
72 
73 /****************************************************************************/
74 
MonOtherGatherData(double * cf_this)75 void MonOtherGatherData(double *cf_this)
76 {
77     Log(LOG_LEVEL_VERBOSE, "Gathering data from static Nova monitoring probes.");
78 
79     for (size_t i = 0; i < sizeof(ENTERPRISE_PROBES) / sizeof(ENTERPRISE_PROBES[0]); ++i)
80     {
81         const char *probename = ENTERPRISE_PROBES[i].name;
82         ProbeGatherData gatherer = ENTERPRISE_PROBES_GATHERERS[i];
83 
84         if (gatherer)
85         {
86             Log(LOG_LEVEL_VERBOSE, " * %s", probename);
87             (*gatherer) (cf_this);
88         }
89     }
90     Log(LOG_LEVEL_VERBOSE, "Gathering data from static Nova monitoring probes is finished.");
91 }
92