mirror of
https://github.com/limosek/zaf.git
synced 2024-11-21 18:09:06 +01:00
First scripts
This commit is contained in:
parent
b048d26533
commit
5e566a2046
38
README.md
38
README.md
@ -1,53 +1,41 @@
|
||||
# zaf
|
||||
Zabbix Agent Framework
|
||||
# Zabbix Agent Framework
|
||||
|
||||
This tool is used to maintain external zabbix checks in *one place*. There are lot of places where it is possible to download many external checks.
|
||||
But there is problem with installation, update and centralised management. This tool should do all of this in easy steps.
|
||||
But there is problem with installation, update and centralised management. This tool should do all of this in easy steps. Today is is in devel stage and not everything works.
|
||||
I will try to make it working :)
|
||||
|
||||
## Example
|
||||
Best way how to explain everything is example. Supposing we are working on debian-like system.
|
||||
```
|
||||
sudo apt-get install software-properties-common
|
||||
sudo add-apt-repository xxx/zaf
|
||||
sudo apt-get update
|
||||
sudo apt-get install zaf
|
||||
sudo zaf add-repository http://some.other.project/
|
||||
sudo zaf update
|
||||
sudo zaf install process-discovery
|
||||
sudo zaf upgrade
|
||||
curl https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sudo sh
|
||||
sudo zaf install process-info
|
||||
sudo zaf install http://other.check.domain/check/
|
||||
zaf make-deb
|
||||
zaf make-opkg
|
||||
zaf make-rpm
|
||||
zaf self-upgrade
|
||||
```
|
||||
|
||||
## Zaf APT repository
|
||||
Zaf APT repository is for easier installation of zaf itself. It can be skipped or zaf can be installed directly.
|
||||
|
||||
## Zaf repository
|
||||
Zaf repository is place where zaf plugins are located. There can be lot of repositories. In fact, every zaf plugin can have its own repo.
|
||||
|
||||
## Zaf plugin
|
||||
Zaf plugin is set of configuration options and binaries which are needed for specific checks. For example, to monitor postfix, we need some cron job which is automaticaly run and next ti this, some external items which has to be configured.
|
||||
|
||||
## How it works
|
||||
There is central zaf reposirory on github. There are basic checks and zaf code itself. Next to this, each project can have its own zaf structure. Adding url of plugin to zaf will make it useable and updatable.
|
||||
|
||||
## Zaf repository structure
|
||||
Each zaf repository url MUST have this items:
|
||||
```
|
||||
/zaf.md # Documentation
|
||||
/zaf.plugins # List of plugins, one plugin per line
|
||||
```
|
||||
|
||||
## Zaf plugin structure
|
||||
Each zaf plugin url MUST have this items:
|
||||
```
|
||||
/plugin/README.md # Documentation
|
||||
/plugin/control # Control file
|
||||
/plugin/template.xml # Template for Zabbix
|
||||
|
||||
```
|
||||
|
||||
## Zaf control file
|
||||
|
||||
Control files are similar to Debian Control files
|
||||
```
|
||||
will be explained
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
110
install.sh
Executable file
110
install.sh
Executable file
@ -0,0 +1,110 @@
|
||||
#!/bin/sh
|
||||
|
||||
readopt(){
|
||||
echo -n "$1 [$2]: "
|
||||
read opt
|
||||
[ -z "$opt" ] && opt="$2"
|
||||
}
|
||||
|
||||
getrest(){
|
||||
if [ -f "$(dirname $0)/$1" ]; then
|
||||
echo "$(dirname $0)/$1"
|
||||
else
|
||||
wget https://raw.githubusercontent.com/limosek/zaf/master/$1 -O- >${ZAF_TMP_DIR}/$(basename $1)
|
||||
echo ${ZAF_TMP_DIR}/$(basename $1)
|
||||
fi
|
||||
}
|
||||
|
||||
preconf(){
|
||||
echo "Zabbix Agent Framework installer."
|
||||
if ! which zabbix_agentd >/dev/null; then
|
||||
echo "Zabbix agent not installed? Exiting."
|
||||
exit 3
|
||||
fi
|
||||
if ! [ -f "/etc/zaf.conf" ] || [ -n "$1" ]; then
|
||||
readopt "Tmp directory" "/tmp/zaf"
|
||||
ZAF_TMP_DIR="$opt"
|
||||
|
||||
readopt "Libraries directory" "/usr/lib/zaf"
|
||||
ZAF_LIB_DIR="$opt"
|
||||
|
||||
readopt "Plugins directory" "${ZAF_LIB_DIR}/plugins"
|
||||
ZAF_PLUGINS_DIR="$opt"
|
||||
|
||||
readopt "Git plugins directory" "${ZAF_LIB_DIR}/repo"
|
||||
ZAF_REPO_DIR="$opt"
|
||||
|
||||
readopt "Plugins repository" "https://github.com/limosek/zaf.git/plugins"
|
||||
ZAF_PLUGINS_REPO="$opt"
|
||||
|
||||
readopt "Default plugins to install" "process-info"
|
||||
ZAF_DEFAULT_PLUGINS="$opt"
|
||||
|
||||
readopt "Zabbix agent config" "/etc/zabbix/zabbix_agentd.conf"
|
||||
ZAF_AGENT_CONFIG="$opt"
|
||||
|
||||
readopt "Zabbix agent restart cmd" "service zabbix-agent restart"
|
||||
ZAF_AGENT_RESTART="$opt"
|
||||
|
||||
if which sudo >/dev/null; then
|
||||
sudo=1
|
||||
else
|
||||
sudo=0
|
||||
fi
|
||||
readopt "Use sudo" "$sudo"
|
||||
ZAF_SUDO="$opt"
|
||||
else
|
||||
echo "Skipping configuration. Config file /etc/zaf.conf already exists."
|
||||
. /etc/zaf.conf
|
||||
fi
|
||||
if [ "$USERNAME" = "root" ]; then
|
||||
echo "We are root. That is OK."
|
||||
else
|
||||
if [ "$ZAF_SUDO" = 1 ] && ! which sudo >/dev/null; then
|
||||
echo "We are not root and sudo is not installed. Cannot continue."
|
||||
exit 2
|
||||
fi
|
||||
echo "We are not root. Assuming we have enough privileges."
|
||||
fi
|
||||
echo "ZAF_LIB_DIR='$ZAF_LIB_DIR'" >/etc/zaf.conf || { echo "Not enough privileges. Please become root!"; exit 2; }
|
||||
echo "ZAF_TMP_DIR='$ZAF_TMP_DIR'" >>/etc/zaf.conf
|
||||
echo "ZAF_PLUGINS_DIR='$ZAF_PLUGINS_DIR'" >>/etc/zaf.conf
|
||||
echo "ZAF_REPO_DIR='$ZAF_REPO_DIR'" >>/etc/zaf.conf
|
||||
echo "ZAF_PLUGINS_REPO='$ZAF_PLUGINS_REPO'" >>/etc/zaf.conf
|
||||
echo "ZAF_AGENT_RESTART='$ZAF_AGENT_RESTART'" >>/etc/zaf.conf
|
||||
echo "ZAF_AGENT_CONFIG='$ZAF_AGENT_CONFIG'" >>/etc/zaf.conf
|
||||
echo "ZAF_SUDO='$ZAF_SUDO'" >>/etc/zaf.conf
|
||||
}
|
||||
|
||||
case $1 in
|
||||
reconf)
|
||||
preconf force
|
||||
export ZAF_DEFAULT_PLUGINS
|
||||
$0 install
|
||||
;;
|
||||
*)
|
||||
preconf
|
||||
rm -rif ${ZAF_TMP_DIR}
|
||||
install -d ${ZAF_TMP_DIR}
|
||||
install -d ${ZAF_LIB_DIR}
|
||||
install -d ${ZAF_PLUGINS_DIR}
|
||||
if [ -n "${ZAF_PLUGINS_REPO}" ]; then
|
||||
if ! [ -d "${ZAF_REPO_DIR}" ]; then
|
||||
git clone "${ZAF_PLUGINS_REPO}" "${ZAF_REPO_DIR}"
|
||||
else
|
||||
(cd "${ZAF_REPO_DIR}" && git pull)
|
||||
fi
|
||||
fi
|
||||
install $(getrest lib/zaf.lib.sh) ${ZAF_LIB_DIR}/
|
||||
mkdir -p ${ZAF_PLUGINS_DIR}
|
||||
install $(getrest zaf) /usr/bin
|
||||
echo "Install OK. Installing plugins (${ZAF_DEFAULT_PLUGINS})."
|
||||
for plugin in ${ZAF_DEFAULT_PLUGINS}; do
|
||||
/usr/bin/zaf install $plugin || exit $?
|
||||
done
|
||||
echo "Done"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
15
lib/zaf.lib.sh
Normal file
15
lib/zaf.lib.sh
Normal file
@ -0,0 +1,15 @@
|
||||
# Update repo
|
||||
zaf_update_repo() {
|
||||
cd ${ZAF_REPO_DIR} && git pull
|
||||
}
|
||||
|
||||
# List installed plugins
|
||||
zaf_list_installed_plugins() {
|
||||
cd ${ZAF_PLUGINS_DIR}; ls -d
|
||||
}
|
||||
|
||||
# Install plugin.
|
||||
# Parameter is url, directory or plugin name (will be searched in default plugin dir)
|
||||
zaf_install_plugin() {
|
||||
a
|
||||
}
|
8
plugins/process-info/README.md
Normal file
8
plugins/process-info/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Zaf plugin for detailed process info
|
||||
This plugin is used to monitor process activity on linux based systems. It supports autodiscovery of processes and next to this it will show CPU and memory usage of each process.
|
||||
Please note that this plugin is very simple plugin for domonstrating possibilities. It cannot catch all processes because it discovers processes in regular intervals and if process will start and end between this time, it will not be autodiscovered.
|
||||
|
||||
## Usage
|
||||
|
||||
zaf intall process-list
|
||||
|
15
plugins/process-info/control
Normal file
15
plugins/process-info/control
Normal file
@ -0,0 +1,15 @@
|
||||
Plugin: process-info
|
||||
|
||||
Maintainer: Lukas Macura <lukas@macura.cz>
|
||||
|
||||
Item: cpu[*]
|
||||
This item will return cpu usage of given process. In zabbix, it will be prefixed automaticaly by plugin name (processlist.cpu)
|
||||
Item-cmd-cpu[*]: TOTAL=0; for PROC in $(/bin/ps u -C $1 | /bin/grep -e '^$2' | /usr/bin/awk '{ print $$3 }'); do TOTAL=$(echo "$TOTAL $PROC" | /usr/bin/awk '{print $$1 + $$2}') ; done; echo $TOTAL
|
||||
|
||||
Item: discovery
|
||||
Discovery of runing processes
|
||||
Item-cmd-discovery: echo "{\n \"data\":[" ; /bin/ps --no-headers caux | /usr/bin/awk '{ print " { \"{#PSUSER}\":\"" $1 "\", \"{#PSNAME}\":\"" $11 "\" },"}' | /usr/bin/sort | /usr/bin/uniq | /bin/sed -e 's/\//\\\//g' -e '$s/.$//' ; echo " ]\n}"
|
||||
|
||||
Binary-Depends: echo ps awk sort uniq sed
|
||||
|
||||
|
204
plugins/process-info/template.xml
Normal file
204
plugins/process-info/template.xml
Normal file
@ -0,0 +1,204 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<zabbix_export>
|
||||
<version>3.0</version>
|
||||
<date>2016-03-23T09:37:42Z</date>
|
||||
<groups>
|
||||
<group>
|
||||
<name>Templates</name>
|
||||
</group>
|
||||
</groups>
|
||||
<templates>
|
||||
<template>
|
||||
<template>Template Zaf processinfo</template>
|
||||
<name>Template Zaf processinfo</name>
|
||||
<description/>
|
||||
<groups>
|
||||
<group>
|
||||
<name>Templates</name>
|
||||
</group>
|
||||
</groups>
|
||||
<applications>
|
||||
<application>
|
||||
<name>Process Statistics</name>
|
||||
</application>
|
||||
</applications>
|
||||
<items/>
|
||||
<discovery_rules>
|
||||
<discovery_rule>
|
||||
<name>Process Discovery</name>
|
||||
<type>0</type>
|
||||
<snmp_community/>
|
||||
<snmp_oid/>
|
||||
<key>ps.discovery</key>
|
||||
<delay>300</delay>
|
||||
<status>0</status>
|
||||
<allowed_hosts/>
|
||||
<snmpv3_contextname/>
|
||||
<snmpv3_securityname/>
|
||||
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
||||
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
||||
<snmpv3_authpassphrase/>
|
||||
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
||||
<snmpv3_privpassphrase/>
|
||||
<delay_flex/>
|
||||
<params/>
|
||||
<ipmi_sensor/>
|
||||
<authtype>0</authtype>
|
||||
<username/>
|
||||
<password/>
|
||||
<publickey/>
|
||||
<privatekey/>
|
||||
<port/>
|
||||
<filter>
|
||||
<evaltype>0</evaltype>
|
||||
<formula/>
|
||||
<conditions/>
|
||||
</filter>
|
||||
<lifetime>30</lifetime>
|
||||
<description>Discovers running processes via ps.
|
||||
Returns the {#PSNAME} and {#PSUSER} discovery macros which return the process name and owning user respectively.</description>
|
||||
<item_prototypes>
|
||||
<item_prototype>
|
||||
<name>CPU usage of $1 processes owned by $2</name>
|
||||
<type>0</type>
|
||||
<snmp_community/>
|
||||
<multiplier>0</multiplier>
|
||||
<snmp_oid/>
|
||||
<key>proc.cpu[{#PSNAME},{#PSUSER}]</key>
|
||||
<delay>60</delay>
|
||||
<history>14</history>
|
||||
<trends>365</trends>
|
||||
<status>0</status>
|
||||
<value_type>0</value_type>
|
||||
<allowed_hosts/>
|
||||
<units>%</units>
|
||||
<delta>0</delta>
|
||||
<snmpv3_contextname/>
|
||||
<snmpv3_securityname/>
|
||||
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
||||
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
||||
<snmpv3_authpassphrase/>
|
||||
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
||||
<snmpv3_privpassphrase/>
|
||||
<formula>1</formula>
|
||||
<delay_flex/>
|
||||
<params/>
|
||||
<ipmi_sensor/>
|
||||
<data_type>0</data_type>
|
||||
<authtype>0</authtype>
|
||||
<username/>
|
||||
<password/>
|
||||
<publickey/>
|
||||
<privatekey/>
|
||||
<port/>
|
||||
<description/>
|
||||
<inventory_link>0</inventory_link>
|
||||
<applications>
|
||||
<application>
|
||||
<name>Process Statistics</name>
|
||||
</application>
|
||||
</applications>
|
||||
<valuemap/>
|
||||
<logtimefmt/>
|
||||
<application_prototypes/>
|
||||
</item_prototype>
|
||||
<item_prototype>
|
||||
<name>Memory usage of $1 processes owned by $2</name>
|
||||
<type>0</type>
|
||||
<snmp_community/>
|
||||
<multiplier>0</multiplier>
|
||||
<snmp_oid/>
|
||||
<key>proc.mem[{#PSNAME},{#PSUSER},,]</key>
|
||||
<delay>60</delay>
|
||||
<history>14</history>
|
||||
<trends>365</trends>
|
||||
<status>0</status>
|
||||
<value_type>3</value_type>
|
||||
<allowed_hosts/>
|
||||
<units>B</units>
|
||||
<delta>0</delta>
|
||||
<snmpv3_contextname/>
|
||||
<snmpv3_securityname/>
|
||||
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
||||
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
||||
<snmpv3_authpassphrase/>
|
||||
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
||||
<snmpv3_privpassphrase/>
|
||||
<formula>1</formula>
|
||||
<delay_flex/>
|
||||
<params/>
|
||||
<ipmi_sensor/>
|
||||
<data_type>0</data_type>
|
||||
<authtype>0</authtype>
|
||||
<username/>
|
||||
<password/>
|
||||
<publickey/>
|
||||
<privatekey/>
|
||||
<port/>
|
||||
<description/>
|
||||
<inventory_link>0</inventory_link>
|
||||
<applications>
|
||||
<application>
|
||||
<name>Process Statistics</name>
|
||||
</application>
|
||||
</applications>
|
||||
<valuemap/>
|
||||
<logtimefmt/>
|
||||
<application_prototypes/>
|
||||
</item_prototype>
|
||||
<item_prototype>
|
||||
<name>Number of $1 processes owned by $2</name>
|
||||
<type>0</type>
|
||||
<snmp_community/>
|
||||
<multiplier>0</multiplier>
|
||||
<snmp_oid/>
|
||||
<key>proc.num[{#PSNAME},{#PSUSER},,]</key>
|
||||
<delay>60</delay>
|
||||
<history>14</history>
|
||||
<trends>365</trends>
|
||||
<status>0</status>
|
||||
<value_type>3</value_type>
|
||||
<allowed_hosts/>
|
||||
<units/>
|
||||
<delta>0</delta>
|
||||
<snmpv3_contextname/>
|
||||
<snmpv3_securityname/>
|
||||
<snmpv3_securitylevel>0</snmpv3_securitylevel>
|
||||
<snmpv3_authprotocol>0</snmpv3_authprotocol>
|
||||
<snmpv3_authpassphrase/>
|
||||
<snmpv3_privprotocol>0</snmpv3_privprotocol>
|
||||
<snmpv3_privpassphrase/>
|
||||
<formula>1</formula>
|
||||
<delay_flex/>
|
||||
<params/>
|
||||
<ipmi_sensor/>
|
||||
<data_type>0</data_type>
|
||||
<authtype>0</authtype>
|
||||
<username/>
|
||||
<password/>
|
||||
<publickey/>
|
||||
<privatekey/>
|
||||
<port/>
|
||||
<description/>
|
||||
<inventory_link>0</inventory_link>
|
||||
<applications>
|
||||
<application>
|
||||
<name>Process Statistics</name>
|
||||
</application>
|
||||
</applications>
|
||||
<valuemap/>
|
||||
<logtimefmt/>
|
||||
<application_prototypes/>
|
||||
</item_prototype>
|
||||
</item_prototypes>
|
||||
<trigger_prototypes/>
|
||||
<graph_prototypes/>
|
||||
<host_prototypes/>
|
||||
</discovery_rule>
|
||||
</discovery_rules>
|
||||
<macros/>
|
||||
<templates/>
|
||||
<screens/>
|
||||
</template>
|
||||
</templates>
|
||||
</zabbix_export>
|
34
zaf
Executable file
34
zaf
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Some defaults
|
||||
|
||||
ZAF_AGENT_RESTART="service zabbix-agentd restart"
|
||||
ZAF_AGENT_CONFIG="/etc/zabbix/zabbix_agentd.conf"
|
||||
ZAF_LIB_DIR="/usr/lib/zaf/"
|
||||
ZAF_PLUGINS_DIR="/usr/lib/zaf/plugins/"
|
||||
|
||||
if [ -f /etc/zaf.conf ]; then
|
||||
. /etc/zaf.conf
|
||||
fi
|
||||
|
||||
. ${ZAF_LIB_DIR}/zaf.lib.sh
|
||||
|
||||
case $1 in
|
||||
update)
|
||||
zaf_update_repo
|
||||
;;
|
||||
|
||||
list-installed)
|
||||
zaf_list_installed_plugins
|
||||
;;
|
||||
|
||||
install)
|
||||
zaf_install_plugin "$2"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "$0 update"
|
||||
echo "$0 install plugin"
|
||||
;;
|
||||
esac
|
||||
|
Loading…
Reference in New Issue
Block a user