1
0
mirror of https://github.com/limosek/zaf.git synced 2024-11-13 05:59:06 +01:00

Repaired docs, added cron

This commit is contained in:
Lukas Macura 2016-04-13 12:42:12 +02:00
parent 9ed9e990ed
commit ce4df86f46
4 changed files with 42 additions and 22 deletions

View File

@ -19,25 +19,24 @@ So zaf is here for you :)
* Sharing code. Many zabbix external checks share common shell functions.
* Simplification of userparameter functions (does not have to be one-line long code)
* Zabbix discovery simplification. Creating zabbix item for discovery is not so easy in shell based system and result is not nice. But you can use framework function to do so.
* OS packaging support (in future).
* Zabbix agent autoinstallation and autoconfiguration suitable to use in puppet or another tool
* OS packaging support
## Installing Zaf
You need to be root and you must have curl installed on your system. Depending on your system, github certificates may not be available so you have to use *-k* option for curl (insecure). Default installation type is silent. So there will be no questions and everything will be autodetected. This simple command should be used on most systems:
```
curl -k https://raw.githubusercontent.com/limosek/zaf/1.0/install.sh | sh
curl -k https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sh
```
### Install options and autoconfiguration
General parameters for install.sh on any system (simplest way how to install)
```
curl -k https://raw.githubusercontent.com/limosek/zaf/1.0/install.sh | \
curl -k https://raw.githubusercontent.com/limosek/zaf/master/install.sh | \
sh -s {auto|interactive|debug-auto|debug-interactive} [Agent-Options] [Zaf-Options]
```
or use git version:
```
git clone https://github.com/limosek/zaf.git; cd zaf; git checkout 1.0
git clone https://github.com/limosek/zaf.git; cd zaf; git checkout master
./install.sh {auto|interactive|debug-auto|debug-interactive} [Agent-Options] [Zaf-Options]
Agent-Options: Z_Option=value [...]
Zaf-Options: ZAF_OPT=value [...]
@ -68,7 +67,7 @@ Now everything was tested on Debian and OpenWrt. If somebody is interrested in,
Suppose you want to autoinstall agent on clean system. You need only curl installed. Everything else is one-cmd process.
This command will install zaf, install zabbix-agent if necessary and sets zabbix variables on agent to reach server. This command can be automatized by puppet or another deploying system.
```
curl -k https://raw.githubusercontent.com/limosek/zaf/1.0/install.sh | sh -s auto \
curl -k https://raw.githubusercontent.com/limosek/zaf/master/install.sh | sh -s auto \
Z_Server=zabbix.server.local \
Z_ServerActive=zabbix.server.local \
Z_HostnameItem=system.hostname Z_RefreshActiveChecks=60 \
@ -80,10 +79,10 @@ You can make your own deb package with preconfigured option. It is up to you to
```
git clone https://github.com/limosek/zaf.git \
&& cd zaf \
&& git checkout 1.0 \
&& git checkout master \
&& git clone https://github.com/limosek/zaf-plugins.git \
&& make deb PLUGINS="./zaf-plugins/fsx" IPLUGINS="zaf" ZAF_OPTIONS="ZAF_GIT=0" AGENT_OPTIONS="Z_Server=zabbix.server Z_ServerActive=zabbix.server Z_StartAgents=8"
sudo dpkg -i out/zaf-1.0.deb
sudo dpkg -i out/zaf-1.1master.deb
```
General usage:
```
@ -125,7 +124,7 @@ During plugin installation, zaf will check all dependencies, do install binaries
Zaf binary can be installed on any system from openwrt to big system. It has minimal dependencies and is shell based. Is has minimal size (up to 50kb of code). It can be used for installing, removing and testing zaf plugin items. Zaf should be run as root.
```
zaf
zaf Version 1.0. Please use some of this commands:
zaf Version 1.1master. Please use some of this commands:
zaf update To update repo
zaf plugins To list installed plugins
zaf show [plugin] To show installed plugins or plugin info

View File

@ -11,7 +11,7 @@ zaf_cache_clean(){
}
# Get cache key from requested param
zaf_cachekey(){
zaf_cache_key(){
echo "$1" | md5sum - | cut -d ' ' -f 1
}
@ -23,7 +23,7 @@ zaf_tocache(){
local key
local value
local lifetime
key=$(zaf_cachekey "$1")
key=$(zaf_cache_key "$1")
echo "$2" >$ZAF_CACHE_DIR/$key
echo "$1" >$ZAF_CACHE_DIR/$key.key
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.tme
@ -36,13 +36,25 @@ zaf_tocache(){
zaf_tocache_stdin(){
local key
local lifetime
key=$(zaf_cachekey "$1")
key=$(zaf_cache_key "$1")
cat >$ZAF_CACHE_DIR/$key
echo "$1" >$ZAF_CACHE_DIR/$key.key
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.tme
zaf_trc "Cache: Saving entry $1($key)"
cat $ZAF_CACHE_DIR/$key
if [ -s $ZAF_CACHE_DIR/$key ]; then
zaf_trc "Cache: Saving entry $1($key)"
echo "$1" >$ZAF_CACHE_DIR/$key.key
touch -m -d "$3 seconds" $ZAF_CACHE_DIR/$key.tme
cat $ZAF_CACHE_DIR/$key
else
rm $ZAF_CACHE_DIR/$key
fi
}
# Remove entry from cache
# $1 key
zaf_cache_delentry(){
local key
key=$(zaf_cache_key "$1")
zaf_trc "Cache: removing $1($key) from cache"
rm -f "$ZAF_CACHE_DIR/$key*"
}
# Get object from cache
@ -50,7 +62,7 @@ zaf_tocache_stdin(){
zaf_fromcache(){
local key
local value
key=$(zaf_cachekey "$1")
key=$(zaf_cache_key "$1")
if [ -f $ZAF_CACHE_DIR/$key ]; then
if [ "$ZAF_CACHE_DIR/$key.tme" -nt "$ZAF_CACHE_DIR/$key" ]; then
zaf_trc "Cache: serving $1($key) from cache"

View File

@ -89,6 +89,9 @@ zaf_ctrl_check_deps() {
zaf_ctrl_sudo() {
local pdir
local plugin
local sudo
local cmd
local parms
if ! which sudo >/dev/null; then
zaf_wrn "Sudo needed bud not installed?"
@ -96,9 +99,14 @@ zaf_ctrl_sudo() {
pdir="$3"
plugin=$1
zaf_dbg "Installing sudoers entry $ZAF_SUDOERSD/zaf_$plugin"
(echo -n "zabbix ALL=NOPASSWD:SETENV: "
zaf_ctrl_get_global_option $2 "Sudo" | zaf_far '{PLUGINDIR}' "${plugindir}";
echo ) >$ZAF_SUDOERSD/zaf_$plugin
sudo=$(zaf_ctrl_get_global_option $2 "Sudo" | zaf_far '{PLUGINDIR}' "${plugindir}")
cmd=$(echo $sudo | cut -d ' ' -f 1)
parms=$(echo $sudo | cut -d ' ' -f 2-)
if which $cmd >/dev/null ; then
(echo "zabbix ALL=NOPASSWD:SETENV: $(which $cmd) $(echo $parms | tr '%' '*')";echo) >$ZAF_SUDOERSD/zaf_$plugin
else
zaf_wrn "Cannot find binary $cmd for sudo. Ignoring sudo."
fi
}
# Install crontab config from control

View File

@ -273,6 +273,7 @@ zaf_install_plugin() {
zaf_ctrl_check_deps "${control}"
zaf_ctrl_install "$url" "${control}" "${plugindir}"
zaf_ctrl_sudo "$plugin" "${control}" "${plugindir}"
zaf_ctrl_cron "$plugin" "${control}" "${plugindir}"
zaf_ctrl_generate_cfg "${control}" "${plugin}" \
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
@ -388,10 +389,10 @@ zaf_precache_item() {
}
zaf_remove_plugin() {
! [ -d ${ZAF_PLUGINS_DIR}/$1 ] && { zaf_err "Plugin $1 not installed!"; }
! zaf_is_plugin $1 && { zaf_err "Plugin $1 not installed!"; }
zaf_wrn "Removing plugin $1"
rm -rf ${ZAF_PLUGINS_DIR}/$1
rm -f ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
rm -f ${ZAF_AGENT_CONFIGD}/zaf_$1.conf ${ZAF_CROND}/zaf_$1 ${ZAF_SUDOERSD}/zaf_$1
}
zaf_tolower() {