summaryrefslogtreecommitdiffstats
path: root/plugins/check_pgsql.d/config.h
blob: 7c1ff55aa294d934cfc13a1a7e7a99a3de9fb5b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#include "../../config.h"
#include "perfdata.h"
#include "thresholds.h"
#include <stddef.h>
#include <pg_config_manual.h>

#define DEFAULT_DB "template1"

enum {
	DEFAULT_WARN = 2,
	DEFAULT_CRIT = 8,
};

typedef struct {
	char *pghost;    /* host name of the backend server */
	char *pgport;    /* port of the backend server */
	char *pgoptions; /* special options to start up the backend server */
	char *pgtty;     /* debugging tty for the backend server */
	char dbName[NAMEDATALEN];
	char *pguser;
	char *pgpasswd;
	char *pgparams;
	char *pgquery;
	char *pgqueryname;

	mp_thresholds time_thresholds;
	mp_thresholds qthresholds;
} check_pgsql_config;

/* begin, by setting the parameters for a backend connection if the
 * parameters are null, then the system will try to use reasonable
 * defaults by looking up environment variables or, failing that,
 * using hardwired constants
 * this targets  .pgoptions and .pgtty
 */

check_pgsql_config check_pgsql_config_init() {
	check_pgsql_config tmp = {
		.pghost = NULL,
		.pgport = NULL,
		.pgoptions = NULL,
		.pgtty = NULL,
		.dbName = DEFAULT_DB,
		.pguser = NULL,
		.pgpasswd = NULL,
		.pgparams = NULL,
		.pgquery = NULL,
		.pgqueryname = NULL,

		.time_thresholds = mp_thresholds_init(),
		.qthresholds = mp_thresholds_init(),
	};

	mp_range tmp_range = mp_range_init();
	tmp_range = mp_range_set_end(tmp_range, mp_create_pd_value(DEFAULT_WARN));
	tmp.time_thresholds = mp_thresholds_set_warn(tmp.time_thresholds, tmp_range);

	tmp_range = mp_range_set_end(tmp_range, mp_create_pd_value(DEFAULT_CRIT));
	tmp.time_thresholds = mp_thresholds_set_crit(tmp.time_thresholds, tmp_range);

	return tmp;
}