mirror of
https://github.com/limosek/zaf.git
synced 2024-12-04 08:15:34 +01:00
Plugin installation is possible offline
Plugin postconfiguration will be called on zaf agent-config
This commit is contained in:
parent
3e2f1502d1
commit
0ef05853a4
@ -81,6 +81,7 @@ ZAF_ZBXAPI_URL|Zabbix API url|http://localhost/zabbix/api_jsonrpc.php
|
|||||||
ZAF_ZBXAPI_USER|Zabbix API user|zaf
|
ZAF_ZBXAPI_USER|Zabbix API user|zaf
|
||||||
ZAF_ZBXAPI_PASS|Zabbix API password|empty
|
ZAF_ZBXAPI_PASS|Zabbix API password|empty
|
||||||
ZAF_ZBXAPI_AUTHTYPE|Zabbix API authentication type|internal
|
ZAF_ZBXAPI_AUTHTYPE|Zabbix API authentication type|internal
|
||||||
|
ZAF_PLUGINS|Plugins to autoinstall|empty
|
||||||
|
|
||||||
Installer will try to autoguess suitable config options for your system.
|
Installer will try to autoguess suitable config options for your system.
|
||||||
Now everything was tested on Debian and OpenWrt. If somebody is interrested in, you can help and test with some rpm specific functions. Remember that on some systems, default zabbix agent config is empty so you *need to* enter essential config options as parameters.
|
Now everything was tested on Debian and OpenWrt. If somebody is interrested in, you can help and test with some rpm specific functions. Remember that on some systems, default zabbix agent config is empty so you *need to* enter essential config options as parameters.
|
||||||
|
15
deb.mk
15
deb.mk
@ -28,7 +28,7 @@ deb-control:
|
|||||||
deb-scripts:
|
deb-scripts:
|
||||||
@. lib/zaf.lib.sh; \
|
@. lib/zaf.lib.sh; \
|
||||||
. lib/ctrl.lib.sh; \
|
. lib/ctrl.lib.sh; \
|
||||||
cat files/debian/postinst.template | zaf_far '{PLUGINS}' "$(PLUGINS)" | zaf_far "{IPLUGINS}" "$(IPLUGINS)" | zaf_far '{ZAF_LIB_DIR}' "/usr/lib/zaf" >$(DEBIAN_CTRL)/postinst
|
cat files/debian/postinst.template >$(DEBIAN_CTRL)/postinst
|
||||||
@chmod +x $(DEBIAN_CTRL)/postinst
|
@chmod +x $(DEBIAN_CTRL)/postinst
|
||||||
@cp files/debian/preinst.template $(DEBIAN_CTRL)/preinst
|
@cp files/debian/preinst.template $(DEBIAN_CTRL)/preinst
|
||||||
@chmod +x $(DEBIAN_CTRL)/preinst
|
@chmod +x $(DEBIAN_CTRL)/preinst
|
||||||
@ -37,20 +37,12 @@ deb-scripts:
|
|||||||
|
|
||||||
deb-cp:
|
deb-cp:
|
||||||
@mkdir -p $(DEBIAN_DIR)
|
@mkdir -p $(DEBIAN_DIR)
|
||||||
@set -e; INSTALL_PREFIX=$(DEBIAN_DIR) ZAF_DEBUG=$(ZAF_DEBUG) ./install.sh auto $(ZAF_OPTIONS) $(AGENT_OPTIONS)
|
@set -e; INSTALL_PREFIX=$(DEBIAN_DIR) ZAF_DEBUG=$(ZAF_DEBUG) ./install.sh auto $(ZAF_OPTIONS) ZAF_PLUGINS="$(ZAF_PLUGINS)" $(AGENT_OPTIONS)
|
||||||
@. lib/zaf.lib.sh; \
|
|
||||||
. lib/ctrl.lib.sh; \
|
|
||||||
for p in $(PLUGINS); do \
|
|
||||||
plugin=$$(zaf_ctrl_get_global_option $$p/control.zaf Plugin) ; \
|
|
||||||
mkdir -p $(DEBIAN_DIR)/usr/lib/zaf/prepackaged/$$plugin/; \
|
|
||||||
cp -R $$p/* $(DEBIAN_DIR)/usr/lib/zaf/prepackaged/$$plugin/; \
|
|
||||||
done
|
|
||||||
@cat lib/*lib.sh install.sh >$(DEBIAN_DIR)/usr/lib/zaf/install.sh
|
@cat lib/*lib.sh install.sh >$(DEBIAN_DIR)/usr/lib/zaf/install.sh
|
||||||
@chmod +x $(DEBIAN_DIR)/usr/lib/zaf/install.sh
|
@chmod +x $(DEBIAN_DIR)/usr/lib/zaf/install.sh
|
||||||
@rm -rf $(DEBIAN_DIR)/tmp
|
@rm -rf $(DEBIAN_DIR)/tmp
|
||||||
@cp $(DEBIAN_DIR)/etc/zaf.conf tmp/zaf.conf
|
@cp $(DEBIAN_DIR)/etc/zaf.conf tmp/zaf.conf
|
||||||
@grep -E "$$(echo $(ZAF_EXPORT_OPTS) | tr ' ' '|')=" tmp/zaf.conf >$(DEBIAN_DIR)/etc/zaf.conf
|
@grep -E "$$(echo $(ZAF_EXPORT_OPTS) | tr ' ' '|')=" tmp/zaf.conf >$(DEBIAN_DIR)/etc/zaf.conf
|
||||||
@echo "ZAF_PREPACKAGED_DIR=\"/usr/lib/zaf/prepackaged\"" >>$(DEBIAN_DIR)/etc/zaf.conf
|
|
||||||
ifneq ($(AGENT_OPTIONS),)
|
ifneq ($(AGENT_OPTIONS),)
|
||||||
@echo "ZAF_AGENT_OPTIONS=\"$(AGENT_OPTIONS)\"" >>$(DEBIAN_DIR)/etc/zaf.conf
|
@echo "ZAF_AGENT_OPTIONS=\"$(AGENT_OPTIONS)\"" >>$(DEBIAN_DIR)/etc/zaf.conf
|
||||||
endif
|
endif
|
||||||
@ -59,8 +51,7 @@ deb-package:
|
|||||||
@dpkg-deb -b $(DEBIAN_DIR) $(DEBIAN_PKG)
|
@dpkg-deb -b $(DEBIAN_DIR) $(DEBIAN_PKG)
|
||||||
@echo "\nCheck configuration:"
|
@echo "\nCheck configuration:"
|
||||||
@cat $(DEBIAN_DIR)/etc/zaf.conf
|
@cat $(DEBIAN_DIR)/etc/zaf.conf
|
||||||
@echo PLUGINS embedded: $(PLUGINS)
|
@echo PLUGINS embedded: $(ZAF_PLUGINS)
|
||||||
@echo PLUGINS in postinst: $(IPLUGINS)
|
|
||||||
@echo
|
@echo
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,19 +2,7 @@
|
|||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
configure)
|
configure)
|
||||||
if [ -f /usr/lib/zaf/install.sh ] && [ -f /etc/zaf.conf ] && [ -f /usr/lib/zaf/zaf.lib.sh ] && which zaf >/dev/null; then
|
zaf agent-config
|
||||||
. /etc/zaf.conf
|
|
||||||
. /usr/lib/zaf/zaf.lib.sh
|
|
||||||
. /usr/lib/zaf/os.lib.sh
|
|
||||||
. /usr/lib/zaf/ctrl.lib.sh
|
|
||||||
cd /usr/lib/zaf && /usr/lib/zaf/install.sh reconf
|
|
||||||
[ -n "{PLUGINS}" ] && for p in {PLUGINS}; do
|
|
||||||
if ! zaf_is_plugin $p;then
|
|
||||||
zaf install $ZAF_PREPACKAGED_DIR/$p;
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
[ -n "{IPLUGINS}" ] && zaf reinstall {IPLUGINS}
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -280,6 +280,7 @@ zaf_configure(){
|
|||||||
zaf_get_option ZAF_ZBXAPI_USER "Zabbix API user" "zaf" "$INSTALL_MODE"
|
zaf_get_option ZAF_ZBXAPI_USER "Zabbix API user" "zaf" "$INSTALL_MODE"
|
||||||
zaf_get_option ZAF_ZBXAPI_PASS "Zabbix API password" "" "$INSTALL_MODE"
|
zaf_get_option ZAF_ZBXAPI_PASS "Zabbix API password" "" "$INSTALL_MODE"
|
||||||
zaf_get_option ZAF_ZBXAPI_AUTHTYPE "Zabbix API authentication type" "internal" "$INSTALL_MODE"
|
zaf_get_option ZAF_ZBXAPI_AUTHTYPE "Zabbix API authentication type" "internal" "$INSTALL_MODE"
|
||||||
|
zaf_get_option ZAF_PLUGINS "Plugins to autoinstall" "" "$INSTALL_MODE"
|
||||||
|
|
||||||
if zaf_is_root && ! [ -x $ZAF_AGENT_BIN ]; then
|
if zaf_is_root && ! [ -x $ZAF_AGENT_BIN ]; then
|
||||||
zaf_err "Zabbix agent ($ZAF_AGENT_BIN) not installed? Use ZAF_AGENT_BIN env variable to specify location. Exiting."
|
zaf_err "Zabbix agent ($ZAF_AGENT_BIN) not installed? Use ZAF_AGENT_BIN env variable to specify location. Exiting."
|
||||||
@ -329,7 +330,11 @@ zaf_configure(){
|
|||||||
zaf_set_option ZAF_ZBXAPI_USER "$ZAF_ZBXAPI_USER"
|
zaf_set_option ZAF_ZBXAPI_USER "$ZAF_ZBXAPI_USER"
|
||||||
zaf_set_option ZAF_ZBXAPI_PASS "$ZAF_ZBXAPI_PASS"
|
zaf_set_option ZAF_ZBXAPI_PASS "$ZAF_ZBXAPI_PASS"
|
||||||
zaf_set_option ZAF_ZBXAPI_AUTHTYPE "$ZAF_ZBXAPI_AUTHTYPE"
|
zaf_set_option ZAF_ZBXAPI_AUTHTYPE "$ZAF_ZBXAPI_AUTHTYPE"
|
||||||
[ -n "$ZAF_PREPACKAGED_DIR" ] && zaf_set_option ZAF_PREPACKAGED_DIR "$ZAF_PREPACKAGED_DIR"
|
if [ -n "$ZAF_PLUGINS" ]; then
|
||||||
|
for p in $ZAF_PLUGINS; do
|
||||||
|
zaf_install_plugin $p
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
if zaf_is_root; then
|
if zaf_is_root; then
|
||||||
zaf_configure_agent $ZAF_AGENT_OPTIONS "$@"
|
zaf_configure_agent $ZAF_AGENT_OPTIONS "$@"
|
||||||
|
@ -84,16 +84,20 @@ zaf_prepare_plugin() {
|
|||||||
local url
|
local url
|
||||||
local plugindir
|
local plugindir
|
||||||
local control
|
local control
|
||||||
|
local pluginname
|
||||||
|
|
||||||
url=$(zaf_get_plugin_url "$1")/control.zaf || exit $?
|
url=$(zaf_get_plugin_url "$1")/control.zaf || exit $?
|
||||||
plugindir="$2"
|
plugindir="$2"
|
||||||
control=${plugindir}/control.zaf
|
control=${plugindir}/control.zaf
|
||||||
zaf_install_dir "$plugindir"
|
zaf_install_dir "$plugindir"
|
||||||
zaf_dbg "Fetching control file from $url ..."
|
zaf_dbg "Fetching control file from $url ..."
|
||||||
if zaf_fetch_url "$url" >"${control}"; then
|
if zaf_fetch_url "$url" >"${INSTALL_PREFIX}/${control}"; then
|
||||||
zaf_ctrl_check_deps "${control}"
|
[ -z "${INSTALL_PREFIX}" ] && zaf_ctrl_check_deps "${control}"
|
||||||
|
pluginname=$(zaf_ctrl_get_global_block <"${INSTALL_PREFIX}/${control}" | zaf_block_get_option Plugin)
|
||||||
|
[ "$(basename $plugindir)" != "$pluginname" ] && zaf_err "prepare_plugin: Plugin name mismach ($plugindir vs $pluginname)!"
|
||||||
|
true
|
||||||
else
|
else
|
||||||
zaf_err "prepare_plugin: Cannot fetch or write control file $control from url $url!"
|
zaf_err "prepare_plugin: Cannot fetch or write control file ${INSTALL_PREFIX}/$control from url $url!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,36 +110,52 @@ zaf_install_plugin() {
|
|||||||
local version
|
local version
|
||||||
|
|
||||||
plugin=$(basename "$1")
|
plugin=$(basename "$1")
|
||||||
tmpplugindir="${ZAF_TMP_DIR}/zaf-installer/$plugin"
|
plugindir="${ZAF_PLUGINS_DIR}/${plugin}"
|
||||||
mkdir -p $tmpplugindir
|
if [ -n "$plugin" ] && zaf_prepare_plugin "$1" $plugindir; then
|
||||||
if zaf_prepare_plugin "$1" "$tmpplugindir"; then
|
zaf_wrn "Installing plugin $plugin"
|
||||||
url=$(zaf_get_plugin_url "$1")
|
zaf_dbg "Source url: $url, Destination dir: $plugindir"
|
||||||
control="$tmpplugindir/control.zaf"
|
control=${plugindir}/control.zaf
|
||||||
plugin=$(zaf_ctrl_get_global_option $control Plugin)
|
[ "$ZAF_DEBUG" -gt 1 ] && zaf_plugin_info "${control}"
|
||||||
version=$(zaf_ctrl_get_global_option $control Version)
|
if [ -z "${INSTALL_PREFIX}" ]; then
|
||||||
plugindir="${ZAF_PLUGINS_DIR}/$plugin"
|
|
||||||
if [ -n "$plugin" ] && zaf_prepare_plugin "$1" $plugindir; then
|
|
||||||
zaf_wrn "Installing plugin $plugin version $version"
|
|
||||||
zaf_dbg "Source url: $url, Destination dir: $plugindir"
|
|
||||||
control=${plugindir}/control.zaf
|
|
||||||
[ "$ZAF_DEBUG" -gt 1 ] && zaf_plugin_info "${control}"
|
|
||||||
zaf_ctrl_check_deps "${control}"
|
zaf_ctrl_check_deps "${control}"
|
||||||
zaf_ctrl_sudo "$plugin" "${control}" "${plugindir}"
|
zaf_ctrl_sudo "$plugin" "${control}" "${plugindir}"
|
||||||
zaf_ctrl_cron "$plugin" "${control}" "${plugindir}"
|
zaf_ctrl_cron "$plugin" "${control}" "${plugindir}"
|
||||||
zaf_ctrl_generate_items_cfg "${control}" "${plugin}" \
|
zaf_ctrl_generate_items_cfg "${control}" "${plugin}" \
|
||||||
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
||||||
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
|
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
|
||||||
zaf_ctrl_generate_extitems_cfg "${control}" "${plugin}"
|
zaf_ctrl_generate_extitems_cfg "${control}" "${plugin}"
|
||||||
zaf_ctrl_install "$url" "${control}" "${plugindir}"
|
|
||||||
else
|
else
|
||||||
zaf_err "Cannot install plugin '$plugin' to $plugindir!"
|
zaf_touch "${plugindir}/needinstall"
|
||||||
fi
|
fi
|
||||||
else
|
zaf_ctrl_install "$url" "${control}" "${plugindir}"
|
||||||
zaf_err "Cannot prepare plugin $1"
|
else
|
||||||
|
zaf_err "Cannot install plugin '$plugin' to $plugindir!"
|
||||||
fi
|
fi
|
||||||
rm -rf $tmpplugindir
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zaf_postinstall_plugin() {
|
||||||
|
local url
|
||||||
|
local plugin
|
||||||
|
local plugindir
|
||||||
|
local tmpplugindir
|
||||||
|
local control
|
||||||
|
local version
|
||||||
|
|
||||||
|
plugin=$(basename "$1")
|
||||||
|
plugindir="${ZAF_PLUGINS_DIR}/${plugin}"
|
||||||
|
control=${plugindir}/control.zaf
|
||||||
|
[ "$ZAF_DEBUG" -gt 1 ] && zaf_plugin_info "${control}"
|
||||||
|
zaf_ctrl_check_deps "${control}"
|
||||||
|
zaf_ctrl_sudo "$plugin" "${control}" "${plugindir}"
|
||||||
|
zaf_ctrl_cron "$plugin" "${control}" "${plugindir}"
|
||||||
|
zaf_ctrl_generate_items_cfg "${control}" "${plugin}" \
|
||||||
|
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
||||||
|
zaf_dbg "Generated ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
|
||||||
|
zaf_ctrl_generate_extitems_cfg "${control}" "${plugin}"
|
||||||
|
zaf_ctrl_install "$url" "${control}" "${plugindir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# List installed plugins
|
# List installed plugins
|
||||||
# $1 - plugin
|
# $1 - plugin
|
||||||
zaf_list_plugins() {
|
zaf_list_plugins() {
|
||||||
|
14
zaf
14
zaf
@ -88,13 +88,21 @@ userparms)
|
|||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
agent-config)
|
agent-config)
|
||||||
|
for p in $(zaf_list_plugins); do
|
||||||
|
if [ -f "$ZAF_PLUGINS_DIR/$p/needinstall" ]; then
|
||||||
|
zaf_wrn "Calling postinstalation of plugin $p"
|
||||||
|
zaf_postinstall_plugin $p && rm -f "$ZAF_PLUGINS_DIR/$p/needinstall"
|
||||||
|
fi
|
||||||
|
done
|
||||||
zaf_wrn "Generating config files in $ZAF_AGENT_CONFIGD ..."
|
zaf_wrn "Generating config files in $ZAF_AGENT_CONFIGD ..."
|
||||||
for plugin in $(zaf_list_plugins); do
|
for plugin in $(zaf_list_plugins); do
|
||||||
plugindir=$ZAF_PLUGINS_DIR/$plugin
|
plugindir=$ZAF_PLUGINS_DIR/$plugin
|
||||||
control=$plugindir/control.zaf
|
control=$plugindir/control.zaf
|
||||||
zaf_dbg "Generating ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
|
if ! [ -f "${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf" ] || [ "$control" -nt "${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf" ] || [ -n "$2" ]; then
|
||||||
zaf_ctrl_generate_items_cfg "${control}" "${plugin}" \
|
zaf_dbg "Generating ${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf"
|
||||||
|
zaf_ctrl_generate_items_cfg "${control}" "${plugin}" \
|
||||||
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
| zaf_far '{PLUGINDIR}' "${plugindir}" >${ZAF_AGENT_CONFIGD}/zaf_${plugin}.conf
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
server-config)
|
server-config)
|
||||||
@ -442,7 +450,7 @@ api)
|
|||||||
echo
|
echo
|
||||||
echo "Agent config info commands:"
|
echo "Agent config info commands:"
|
||||||
zaf_hlp "$0 userparms" "See userparms generated from zaf on stdout"
|
zaf_hlp "$0 userparms" "See userparms generated from zaf on stdout"
|
||||||
zaf_hlp "$0 agent-config" "Reconfigure zabbix userparms in $ZAF_AGENT_CONFIGD"
|
zaf_hlp "$0 agent-config [force]" "Reconfigure zabbix userparms in $ZAF_AGENT_CONFIGD"
|
||||||
echo
|
echo
|
||||||
echo "Zaf related commands:"
|
echo "Zaf related commands:"
|
||||||
zaf_hlp "$0 self-upgrade" "To self-upgrade zaf"
|
zaf_hlp "$0 self-upgrade" "To self-upgrade zaf"
|
||||||
|
Loading…
Reference in New Issue
Block a user