Skip to content

Commit ae96031

Browse files
committed
Changes to support new pg.query2.* keys
1 parent a914533 commit ae96031

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

Diff for: ChangeLog

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v1.1.0 19 Aug 2016
2+
3+
* Implemented `pg.query2.*` keys - Rob Brucks
4+
15
v1.0.0 26 Jun 2016
26

37
* Added support for Zabbix v3

Diff for: configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AC_INIT([libzbxpgsql], [1.0.0], [[email protected]])
1+
AC_INIT([libzbxpgsql], [1.1.0], [[email protected]])
22
AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability foreign])
33
m4_pattern_allow([AM_PROG_AR])
44
AM_PROG_AR

Diff for: query.conf

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# file: /etc/libzbxpgsql.d/query.conf
2+
#
3+
# This file contains SQL to be executed by `pg_query2.*` keys
4+
# It is parsed by the C libconfig module
5+
# http://www.hyperrealm.com/main.php?s=libconfig
6+
#
7+
# The format of the file is:
8+
# SQLkey = "SQL statement"
9+
#
10+
# SQL must be enclosed in double quotes. Double quotes
11+
# inside the SQL must be escaped with a backslash.
12+
#
13+
# Any syntax error in the file will prevent the entire
14+
# file from being parsed correctly.
15+
#
16+
# SQL statements can span multiple lines:
17+
# longsql = "select count(*)
18+
# from pg_stat_activity;"
19+
#
20+
# Testing Queries
21+
test1 = "SELECT 'Lorem ipsum dolor';"
22+
test2 = "SELECT pg_backend_pid();"
23+
test3 = "SELECT CAST(1234 AS double precision);"
24+
test4 = "SELECT * FROM pg_database;"

Diff for: src/Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ libzbxpgsql_la_SOURCES = \
1212
pg_namespace.c \
1313
pg_params.c \
1414
pg_query.c \
15+
pg_query2.c \
1516
pg_server.c \
1617
pg_setting.c \
1718
pg_table.c \
@@ -26,6 +27,7 @@ libzbxpgsql_la_CFLAGS = \
2627

2728
libzbxpgsql_la_LDFLAGS = \
2829
-shared \
30+
-lconfig \
2931
-avoid-version
3032

3133
# Prevent install of the redundant *.la files

Diff for: src/libzbxpgsql.c

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ static ZBX_METRIC keys[] =
4646
{"pg.query.integer", CF_HAVEPARAMS, PG_QUERY, ",,SELECT pg_backend_pid();"},
4747
{"pg.query.double", CF_HAVEPARAMS, PG_QUERY, ",,SELECT CAST(1234 AS double precision);"},
4848
{"pg.query.discovery", CF_HAVEPARAMS, PG_QUERY, ",,SELECT * FROM pg_database;"},
49+
50+
// User queries from config file
51+
{"pg.query2.string", CF_HAVEPARAMS, PG_QUERY2, ",,test1"},
52+
{"pg.query2.integer", CF_HAVEPARAMS, PG_QUERY2, ",,test2"},
53+
{"pg.query2.double", CF_HAVEPARAMS, PG_QUERY2, ",,test3"},
54+
{"pg.query2.discovery", CF_HAVEPARAMS, PG_QUERY2, ",,test4"},
4955

5056
// Client connection statistics
5157
{"pg.backends.count", CF_HAVEPARAMS, PG_BACKENDS_COUNT, NULL},

Diff for: src/libzbxpgsql.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
// PostgreSQL headers
2828
#include <libpq-fe.h>
2929

30+
// Reading Config Files
31+
#include <stdio.h>
32+
#include <stdlib.h>
33+
#include <libconfig.h>
34+
3035
// Zabbix source headers
3136
#include <sysinc.h>
3237
#include <module.h>
@@ -108,6 +113,7 @@ int PG_SETTING(AGENT_REQUEST *request, AGENT_RESULT *result);
108113
int PG_SETTING_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result);
109114

110115
int PG_QUERY(AGENT_REQUEST *request, AGENT_RESULT *result);
116+
int PG_QUERY2(AGENT_REQUEST *request, AGENT_RESULT *result);
111117

112118
int PG_BACKENDS_COUNT(AGENT_REQUEST *request, AGENT_RESULT *result);
113119
int PG_BACKENDS_FREE(AGENT_REQUEST *request, AGENT_RESULT *result);
@@ -155,4 +161,4 @@ int PG_INDEX_IDX_BLKS_RATIO(AGENT_REQUEST *request, AGENT_RESULT *result);
155161
int PG_INDEX_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result);
156162
int PG_INDEX_ROWS(AGENT_REQUEST *request, AGENT_RESULT *result);
157163

158-
#endif
164+
#endif

0 commit comments

Comments
 (0)