nstzabbix — Script to manage Zabbix on an NST probe.
nstzabbix
[
-m
TEXT
| --mode
TEXT
] [ --dbimport
FILENAME
] [ --dbimport-rm
[true]|false
] [ --passwd
TEXT
] [ --start
[true]|false
] [ --agent-server
HOSTNAME|IPv4ADDR
] [
-h
[true]|false
| --help
[true]|false
] [
-H
[true]|false
| --help-long
[true]|false
] [
-v
[true]|false
| --verbose
[true]|false
] [ --version
[true]|false
]
The nstzabbix script is used to manage the Zabbix package (a web based system monitoring tool).
There are several things to consider when using nstzabbix:
You must have the database server up and running first (the setup_postgresql script can help with this).
Zabbix is composed of three parts: a server, a web based interface, and agent components. The nstzabbix script is used to setup and configure each of these parts. However, setting up the server and its web based front end is separate from setting up the agent component. It is possible to run both the agent and the server on the same system, but you will need to invoke this script twice, once to setup the server and once to setup the agent.
Once Zabbix has been setup, you access it
by pointing a web browser at https://127.0.0.1:9943/zabbix/
(you may subsitute the external IP address of the system for
"127.0.0.1
" if you are accessing it
remotely).
After the initial setup of the
Zabbix server, one will be able to
log into the server using the "Admin
"
account (leave the password field blank). One should
IMMEDIATELY set the password on the
"Admin
" account and any of the other
accounts which the Zabbix server
creates. NOTE: This only applies if you omitted the
"--dbimport FILE
" option at the time of
setup.
After completing the setup, one can use the systemctl to manage the zabbix-server-pgsql and/or zabbix-agent services.
A simplified interface to this script is provided in the NST web interface.
Here is a example of using nstzabbix to setup a Zabbix server,
check its status, and then remove the Zabbix server from the
system (include the "--verbose
" option to get
additional output):
[root@probe ~]#
nstzabbix -m setup
New password for 'zabbix' database: Retype new password:
[root@probe ~]#
if nstzabbix --mode status; then echo "OK"; fi
[root@probe ~]#
systemctl start zabbix-server-pgsql
[root@probe ~]#
if nstzabbix --mode status; then echo "OK"; fi
OK
[root@probe ~]#
nstzabbix --mode remove
[root@probe ~]#
Here is a example of using nstzabbix to setup the Zabbix agent
on a NST probe. The NST probe will report its status
information to the Zabbix server running
on localhost
.
[root@probe ~]#
nstzabbix -m setup --start --agent-server localhost
[root@probe ~]#
systemctl status zabbix-agent
● zabbix-agent.service - Zabbix Monitor Agent Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-06-06 07:25:28 EDT; 36s ago Main PID: 266021 (zabbix_agentd) Tasks: 6 (limit: 14260) Memory: 3.4M CPU: 31ms CGroup: /system.slice/zabbix-agent.service ├─266021 /usr/sbin/zabbix_agentd -f ├─266023 /usr/sbin/zabbix_agentd: collector [idle 1 sec] ├─266024 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection] ├─266025 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection] ├─266026 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection] └─266027 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] Jun 06 07:25:28 probe systemd[1]: Started Zabbix Monitor Agent. Jun 06 07:25:28 probe zabbix_agentd[266021]: Starting Zabbix Agent [Zabbix server]. Zabbix 5.0.10 (revision 7c3f43904c). Jun 06 07:25:28 probe zabbix_agentd[266021]: Press Ctrl+C to exit.[root@probe ~]#
systemctl stop zabbix-agent
[root@probe ~]#
Here is a example of using nstzabbix to dump the
Zabbix database to "/tmp/zabbix.dump
". The
exported file can serve as a back up and can be restored via:
"-m setup --dbimport
/tmp/zabbix.dump
". Alternatively, it could be copied
to a different NST probe and used to initialize the Zabbix
database on that system.
[root@probe ~]#
nstzabbix --mode dbexport 2>/dev/null >| /tmp/zabbix.dump
[root@probe ~]#
pg_restore --list /tmp/zabbix.dump | head
; ; Archive created at 2021-06-06 07:32:22 EDT ; dbname: zabbix ; TOC Entries: 956 ; Compression: -1 ; Dump Version: 1.14-0 ; Format: CUSTOM ; Integer: 4 bytes ; Offset: 8 bytes ; Dumped from database version: 13.2[root@probe ~]#
This mode of operation can be used to initialize the
Zabbix server and make it accessible
via a web browser. This mode of operation is also used to
configure the Zabbix agent by including
"--agent-server IP
" option. The following
command line options may be used in "setup
"
mode (all are optional):
Provides verbose diagnostic output about what the script is doing. This option can be used regardless of whether one is setting up the Zabbix server or Zabbix agent.
Immediately starts the Zabbix server or agent daemon after completing the setup process. This option can be used regardless of whether one is setting up the Zabbix server or Zabbix agent.
If you have a copy of a Zabbix database you'd
like to use as your intial setup (something you saved
previously via the "--mode dbexport
"
option), you may specify the fully qualified file name
(like: "--dbimport
/tmp/myzabbix.dump
"). This option is only used when
setting up a Zabbix
server.
Include this command line option if you want to remove
the imported "FILE
" (specified in the
"--dbimport FILE
" option) after the
database is imported. This option is only used when setting
up a Zabbix server.
If you don't want to be prompted to provide the
Zabbix database password, you may specify the
password on the command line. Since you seldom need to know
the password, you may also specify "--passwd
RANDOM
" and a random password will be chosen
(NOTE: The password is stored in
"/etc/zabbix/web/zabbix.conf.php
" and
"/etc/zabbix_server.conf
"). This
option is only used when setting up a
Zabbix server.
If you want to setup the
Zabbix agent component instead of
the server, you must include this option. You will need to
specify the IP address or resolvable host name of the
Zabbix server which the agent
should connect to. You may specify more than one server by
using a comma to separate each address - "--agent
server localhost,192.168.1.100
". NOTE: By default,
this mode of operation only prepares the
"/etc/zabbix_agentd.conf
"
configuration file, it won't start the agent unless you
include the "--start
" option as
well. This option is only used when setting up a
Zabbix agent.
This mode of operation is used to tell whether Zabbix
has been setup yet or not. It is written such that there is no
output unless an error occurs or the
"--verbose
" option is also specified. However,
it does exit with 0 if the Zabbix server is setup running
and 1 if not (making it useful to other scripts). The following
command line option(s) may be used in "status
"
mode (all are optional):
Provides verbose diagnostic output about what the script is doing.
NOTE: This does not check the status of the
Zabbix agent. Once may use the
command "systemctl status zabbix-agent
" to
determine if the Zabbix agent is
running.
This mode of operation is used to remove the Zabbix
setup from the system. This will remove the entire Zabbix
database from the SQL server. It is
written such that there is no output unless an error occurs or the
"--verbose
" option is also specified. However,
it does exit with 0 if successful and 1 if not (making it useful
to other scripts). The following command line option(s) may be
used in "remove
" mode (all are
optional):
Provides verbose diagnostic output about what the script is doing.
This does not affect the configuration files found under
the "/etc/zabbix
" directory. It only stops
the Zabbix server and removes its
associated database.
This mode of operation is used to dump a copy of the SQL
database used by Zabbix. No other options are required in
this mode of operation. Since the SQL database is written directly
to the standard output, you can not use the
"--verbose
" option in this mode.
The following demonstrates how to save a copy of the current database, remove the entire Zabbix setup, and then set up Zabbix and initialize it with the previously exported database:
[root@probe ~]#
nstzabbix --mode dbexport 2>/dev/null >| zabbix.dump
[root@probe ~]#
nstzabbix --mode remove
[root@probe ~]#
nstzabbix --mode setup --start --passwd RANDOM --dbimport zabbix.dump
[root@probe ~]#
nstzabbix --mode status && echo running
running
[root@probe ~]#
This mode of operation is used to determine whether the
Zabbix already exists. This mode does
not echo any output to the console (unless the
"--verbose
" option is included). The script
will exit with a return code of 0 if the
Zabbix database exists.
This mode is not typically used from the command line (it is intended to support other scripts), but the following demonstrates how it can be used:
[root@probe ~]#
nstzabbix --mode dbexists -v
+ NOTE + The "zabbix" database was found.
[root@probe ~]#
if nstzabbix --mode dbexists; then echo "Database Found"; fi
Database Found[root@probe ~]#
The following command line options are available:
-m TEXT
] | [--mode TEXT
]
This option controls what
nstzabbix will do. Specify
"status
" (the default), to determine whether
the Zabbix server has been setup and is
running. Specify "setup
" to set up the
Zabbix server or Zabbix
agent on your NST system. Specify "remove
" to
shutdown and remove the Zabbix server
setup. Specify "dbexport
", to dump the
Zabbix database in a form usable for the
"--dbimport FILE
" option. Specify
"dbexists
" mode to determine whether the
Zabbix database exists
(postgresql must already be running).
--dbimport FILENAME
]
By default, the Zabbix management system starts
with a clean slate (nothing configured). One would then need to
spend a lot of time with the initial setup of the Zabbix
management system. This is the default behavior maintained by
this script. Alternatively, one may use the "--dbimport
FILE
" command line option and specify the name of a
initial SQL database dump which they had previously exported via a
previous invocation of "--mode dbexport
". You
may specify the fully qualified path of the initial SQL
database dump.
--dbimport-rm [true]|false
]
This option will remove the database file after importing it (regardless of whether it was successfully loaded or not).
--passwd TEXT
]
This option allows one to set the password used for
access to the "zabbix
" database that will be
created during setup. By default you will be prompted at the
command line. If you specify a password of
"RANDOM
", we will generate a random password
using the pwgen command.
--start [true]|false
]
When this option is combined with "--mode
setup
", the Zabbix server (or agent) will be
immediately started after the initial setup is
complete.
--agent-server HOSTNAME|IPv4ADDR
]
This option can be combined with "--mode
setup
" to setup the Zabbix agent on the NST probe
(instead of the Zabbix server). You need to include the IP
address (or resolvable host name) of the Zabbix server which
will be monitoring this system. If you include the
"--start
" option as well, we will immediately
start the "zabbix-agent" service for you
after setup. One may alternatively use "service
zabbix-agent start|stop
" to control the state of the
agent service after setup. NOTE: You may specify a comma
separate list of IP addresses (or resolvable host names) if you
have more than one Zabbix server that will be connecting to the
agent.
-h [true]|false
] | [--help [true]|false
]
When this option is specified, nstzabbix will display a short one line description of nstzabbix, followed by a short description of each of the supported command line options. After displaying this information nstzabbix will terminate.
-H [true]|false
] | [--help-long [true]|false
]
This option will attempt to pull up additional
nstzabbix documentation within a text based
web browser. You can force which browser we use setting the
environment variable TEXTBROWSER
, otherwise,
we will search for some common ones.
-v [true]|false
] | [--verbose [true]|false
]
When you set this option to true, nstzabbix will produce additional output. This is typically used for diagnostic purposes to help track down when things go wrong.
--version [true]|false
]
If this option is specified, the version number of the script is displayed.
/etc/zabbix_server.conf
Configuration file for the Zabbix server. This script will update this file with information necessary to connect to the zabbix database.
/etc/zabbix_agentd.conf
Configuration file for the Zabbix agent. This script will update this file with the list of Zabbix servers that the agent should register with.
/etc/zabbix/web/zabbix.conf.php
Configuration file used by the Zabbix PHP web interface. This script will update this configuration file with the information necessary to connect to the Zabbix database.