pacemaker
2.0.4-2deceaa3ae
Scalable High-Availability cluster resource manager
lib
services
services_nagios.c
Go to the documentation of this file.
1
/*
2
* Copyright 2010-2019 the Pacemaker project contributors
3
*
4
* The version control history for this file may have further details.
5
*
6
* This source code is licensed under the GNU Lesser General Public License
7
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8
*/
9
10
#include <
crm_internal.h
>
11
12
#ifndef _GNU_SOURCE
13
# define _GNU_SOURCE
14
#endif
15
16
#include <sys/types.h>
17
#include <sys/stat.h>
18
#include <sys/wait.h>
19
#include <errno.h>
20
#include <unistd.h>
21
#include <dirent.h>
22
#include <grp.h>
23
#include <string.h>
24
#include <sys/time.h>
25
#include <sys/resource.h>
26
27
#include "
crm/crm.h
"
28
#include "
crm/common/mainloop.h
"
29
#include "
crm/services.h
"
30
31
#include "
services_private.h
"
32
#include "
services_nagios.h
"
33
34
static
inline
char
*
35
nagios_metadata_name(
const
char
*plugin)
36
{
37
return
crm_strdup_printf
(
NAGIOS_METADATA_DIR
"/%s.xml"
, plugin);
38
}
39
40
GList *
41
services__list_nagios_agents
(
void
)
42
{
43
GList *plugin_list = NULL;
44
GList *result = NULL;
45
46
plugin_list =
services_os_get_directory_list
(
NAGIOS_PLUGIN_DIR
, TRUE, TRUE);
47
48
// Return only the plugins that have metadata
49
for
(GList *gIter = plugin_list; gIter != NULL; gIter = gIter->next) {
50
struct
stat
st
;
51
const
char
*plugin = gIter->data;
52
char
*metadata = nagios_metadata_name(plugin);
53
54
if
(stat(metadata, &
st
) == 0) {
55
result = g_list_append(result, strdup(plugin));
56
}
57
free(metadata);
58
}
59
g_list_free_full(plugin_list, free);
60
return
result;
61
}
62
63
gboolean
64
services__nagios_agent_exists
(
const
char
*
name
)
65
{
66
char
*buf = NULL;
67
gboolean
rc
= FALSE;
68
struct
stat
st
;
69
70
if
(
name
== NULL) {
71
return
rc
;
72
}
73
74
buf =
crm_strdup_printf
(
NAGIOS_PLUGIN_DIR
"/%s"
,
name
);
75
if
(stat(buf, &
st
) == 0) {
76
rc
= TRUE;
77
}
78
79
free(buf);
80
return
rc
;
81
}
82
83
int
84
services__get_nagios_metadata
(
const
char
*
type
,
char
**output)
85
{
86
int
rc
=
pcmk_ok
;
87
FILE *file_strm = NULL;
88
int
start = 0, length = 0, read_len = 0;
89
char
*metadata_file = nagios_metadata_name(
type
);
90
91
file_strm = fopen(metadata_file,
"r"
);
92
if
(file_strm == NULL) {
93
crm_err
(
"Metadata file %s does not exist"
, metadata_file);
94
free(metadata_file);
95
return
-EIO;
96
}
97
98
/* see how big the file is */
99
start = ftell(file_strm);
100
fseek(file_strm, 0L, SEEK_END);
101
length = ftell(file_strm);
102
fseek(file_strm, 0L, start);
103
104
CRM_ASSERT
(length >= 0);
105
CRM_ASSERT
(start == ftell(file_strm));
106
107
if
(length <= 0) {
108
crm_info
(
"%s was not valid"
, metadata_file);
109
free(*output);
110
*output = NULL;
111
rc
= -EIO;
112
113
}
else
{
114
crm_trace
(
"Reading %d bytes from file"
, length);
115
*output = calloc(1, (length + 1));
116
read_len = fread(*output, 1, length, file_strm);
117
if
(read_len != length) {
118
crm_err
(
"Calculated and read bytes differ: %d vs. %d"
,
119
length, read_len);
120
free(*output);
121
*output = NULL;
122
rc
= -EIO;
123
}
124
}
125
126
fclose(file_strm);
127
free(metadata_file);
128
return
rc
;
129
}
st
stonith_t * st
Definition:
pcmk_fence.c:27
rc
int rc
Definition:
pcmk_fence.c:34
services_private.h
type
enum crm_ais_msg_types type
Definition:
internal.h:3
crm_err
#define crm_err(fmt, args...)
Definition:
logging.h:363
services__list_nagios_agents
GList * services__list_nagios_agents(void)
Definition:
services_nagios.c:41
crm_trace
#define crm_trace(fmt, args...)
Definition:
logging.h:369
services_os_get_directory_list
GList * services_os_get_directory_list(const char *root, gboolean files, gboolean executable)
Definition:
services_linux.c:1081
mainloop.h
Wrappers for and extensions to glib mainloop.
NAGIOS_PLUGIN_DIR
#define NAGIOS_PLUGIN_DIR
Definition:
config.h:487
crm_info
#define crm_info(fmt, args...)
Definition:
logging.h:366
crm_strdup_printf
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
NAGIOS_METADATA_DIR
#define NAGIOS_METADATA_DIR
Definition:
config.h:484
services.h
Services API.
CRM_ASSERT
#define CRM_ASSERT(expr)
Definition:
results.h:42
services__nagios_agent_exists
gboolean services__nagios_agent_exists(const char *name)
Definition:
services_nagios.c:64
services_nagios.h
crm_internal.h
name
char * name
Definition:
pcmk_fence.c:30
services__get_nagios_metadata
int services__get_nagios_metadata(const char *type, char **output)
Definition:
services_nagios.c:84
crm.h
A dumping ground.
pcmk_ok
#define pcmk_ok
Definition:
results.h:67
Generated on Thu Oct 29 2020 12:48:48 for pacemaker by
1.8.18