Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zabbix integration #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME
check_pgbackrest - pgBackRest backup check plugin for Nagios
check_pgbackrest - pgBackRest backup check plugin for Nagios and Zabbix (for zabbix integration, see zabbix subfolder)

SYNOPSIS
check_pgbackrest [-s|--service SERVICE] [-S|--stanza NAME]
Expand All @@ -8,7 +8,7 @@ SYNOPSIS

DESCRIPTION
check_pgbackrest is designed to monitor pgBackRest (2.33 and above)
backups from Nagios.
backups from Nagios and Zabbix.

-s, --service SERVICE
The Nagios service to run. See section SERVICES for a description of
Expand Down
2 changes: 1 addition & 1 deletion README.pod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=head1 NAME

check_pgbackrest - pgBackRest backup check plugin for Nagios
check_pgbackrest - pgBackRest backup check plugin for Nagios and zabbix

=head1 SYNOPSIS

Expand Down
4 changes: 4 additions & 0 deletions zabbix/check_pgbackrest_discovery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
A=`echo '- pgbackrest_stanza { "data" : ['`
B=`pgbackrest info | grep -i stanza: | awk '{print "{ \"{#STANZA}\":\"" $2 "\"},"}'`
C=`echo "}]}"`
echo $A$B$C
150 changes: 150 additions & 0 deletions zabbix/pgbackrest_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.4</version>
<date>2021-12-18T16:40:41Z</date>
<groups>
<group>
<uuid>748ad4d098d447d492bb935c907f652f</uuid>
<name>Templates/Databases</name>
</group>
</groups>
<templates>
<template>
<uuid>a2135f96327345bdb1a743502ea5dfbc</uuid>
<template>t_pgbackrest</template>
<name>t_pgbackrest</name>
<description>Template for PGBackRest monitoring</description>
<groups>
<group>
<name>Templates/Databases</name>
</group>
</groups>
<discovery_rules>
<discovery_rule>
<uuid>d2a6cf21a89841f9a6ce81333663afdf</uuid>
<name>stanza discovery</name>
<type>TRAP</type>
<key>pgbackrest_stanza</key>
<delay>0</delay>
<filter>
<conditions>
<condition>
<macro>{#STANZA}</macro>
<formulaid>A</formulaid>
</condition>
</conditions>
</filter>
<item_prototypes>
<item_prototype>
<uuid>3669e006565c46d58ab183b574fe773c</uuid>
<name>Last backup message of {#STANZA}</name>
<type>DEPENDENT</type>
<key>last_backup_message[{#STANZA}]</key>
<delay>0</delay>
<trends>0</trends>
<value_type>TEXT</value_type>
<preprocessing>
<step>
<type>JSONPATH</type>
<parameters>
<parameter>$.*.status.message</parameter>
</parameters>
</step>
<step>
<type>RTRIM</type>
<parameters>
<parameter>]</parameter>
</parameters>
</step>
<step>
<type>LTRIM</type>
<parameters>
<parameter>[</parameter>
</parameters>
</step>
</preprocessing>
<master_item>
<key>pgbackrest_check[&quot;{#STANZA}&quot;]</key>
</master_item>
<tags>
<tag>
<tag>pgbackrest_stanza</tag>
<value>{#STANZA}</value>
</tag>
</tags>
</item_prototype>
<item_prototype>
<uuid>7273dab8b7894592aa26e6aebbdc5481</uuid>
<name>Last backup status of {#STANZA}</name>
<type>DEPENDENT</type>
<key>last_backup_status[{#STANZA}]</key>
<delay>0</delay>
<preprocessing>
<step>
<type>JSONPATH</type>
<parameters>
<parameter>$.*.status.code</parameter>
</parameters>
</step>
<step>
<type>RTRIM</type>
<parameters>
<parameter>]</parameter>
</parameters>
</step>
<step>
<type>LTRIM</type>
<parameters>
<parameter>[</parameter>
</parameters>
</step>
</preprocessing>
<master_item>
<key>pgbackrest_check[&quot;{#STANZA}&quot;]</key>
</master_item>
<tags>
<tag>
<tag>pgbackrest_stanza</tag>
<value>{#STANZA}</value>
</tag>
</tags>
<trigger_prototypes>
<trigger_prototype>
<uuid>6f29bdab8dfd4ff2839f8bee5c642541</uuid>
<expression>last(/t_pgbackrest/last_backup_status[{#STANZA}])&lt;&gt;0</expression>
<name>Last backup status of {#STANZA} not OK</name>
<priority>HIGH</priority>
<description>Last backup of db {#STANZA} was not ok, check pgbackrest for more info</description>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
<item_prototype>
<uuid>aadc833fa4d94b298892a854b0d4085e</uuid>
<name>pgbackrest_check pre {#STANZA}</name>
<type>ZABBIX_ACTIVE</type>
<key>pgbackrest_check[&quot;{#STANZA}&quot;]</key>
<history>1d</history>
<trends>0</trends>
<value_type>TEXT</value_type>
<tags>
<tag>
<tag>pgbackrest_stanza</tag>
<value>{#STANZA}</value>
</tag>
</tags>
<trigger_prototypes>
<trigger_prototype>
<uuid>ba471f6380494b1f9e19e892b995b762</uuid>
<expression>nodata(/t_pgbackrest/pgbackrest_check[&quot;{#STANZA}&quot;],24h)=1</expression>
<name>No data received for 1 day for {#STANZA}</name>
<priority>DISASTER</priority>
<description>No data received for 1 day for {#STANZA}</description>
</trigger_prototype>
</trigger_prototypes>
</item_prototype>
</item_prototypes>
</discovery_rule>
</discovery_rules>
</template>
</templates>
</zabbix_export>
35 changes: 35 additions & 0 deletions zabbix/zabbix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Zabbix

Template is tested with Zabbix 5.4 and Zabbix Agent 5.4 or Zabbix Agent2

## Installation
### check_pgbackrest

Place it in /opt/zabbix/
change owner of directory and script to zabbix user/group as per your system settings

### crontab
Place below line into root crontab. It will execute stanza discovery once a day.

```
0 0 * * * /bin/bash /opt/zabbix/check_pgbackrest_discovery.sh | zabbix_sender -c /etc/zabbix/zabbix_agent2.conf -i -
```

### userparameter
Put to either separate userparameter file or zabbix agent config file.
```
UserParameter=pgbackrest_check[*],sudo perl /opt/zabbix/check_pgbackrest -s archives -S $1 -O json
```

### sudo
Script is executed by zabbix user and it works with pgbackrest which requires root, we need to allow sudo for zabbix agent.

SECURITY! Below line will work but allow zabbix user to execute any command without password, use on your own risk. !

```
zabbix ALL = (root) NOPASSWD:ALL
```

### template
Just import template into Zabbix server and assign to host, for faster results, run discovery manually.
Template name is t_pgbackrest.