From 1a2e768a1c59bd739f1be7c6f89e26715cb68613 Mon Sep 17 00:00:00 2001 From: Mickael-Martin Date: Fri, 1 Mar 2019 10:23:24 +0100 Subject: [PATCH] Update install (function import,link template) --- scripts/install | 80 ++++--------------------------------------------- 1 file changed, 5 insertions(+), 75 deletions(-) diff --git a/scripts/install b/scripts/install index 2303677..5541ee2 100644 --- a/scripts/install +++ b/scripts/install @@ -388,86 +388,16 @@ yunohost app ssowatconf #================================================= # Import Yunohost template #================================================= -ynh_print_info "Import yunohost template" -zabbixFullpath=https://$domain$path_url -localpath=$(find /var/cache/yunohost/ -name "Template_Yunohost.xml") -sudoUserPpath=$(find /var/cache/yunohost/ -name "etc_sudoers.d_zabbix") -confUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_userP_yunohost.conf") -bashUserPpath=$(find /var/cache/yunohost/ -name "etc_zabbix_zabbix_agentd.d_yunohost.sh") - -cp "$sudoUserPpath" /etc/sudoers.d/zabbix -cp "$confUserPpath" /etc/zabbix/zabbix_agentd.d/userP_yunohost.conf -cp "$bashUserPpath" /etc/zabbix/zabbix_agentd.d/yunohost.sh -chmod a+x /etc/zabbix/zabbix_agentd.d/yunohost.sh - -systemctl restart zabbix-agent -curlOptions="-k -s --cookie cookiejar.txt --cookie-jar cookiejar.txt --resolve $domain:443:127.0.0.1" - -curl -L $curlOptions \ - --form "enter=Sign+in" \ - --form "name=Admin" \ - --form "password=zabbix" \ - "$zabbixFullpath/index.php" - -if [ $? -eq 0 ];then - sid=$(curl $curlOptions \ - "$zabbixFullpath/conf.import.php?rules_preset=template" \ - | grep -Po 'name="sid" value="\K([a-z0-9]{16})(?=")' ) - - importState=$(curl $curlOptions \ - --form "config=1" \ - --form "import_file=@$localpath" \ - --form "rules[groups][createMissing]=1" \ - --form "rules[templates][updateExisting]=1" \ - --form "rules[templates][createMissing]=1" \ - --form "rules[templateScreens][updateExisting]=1" \ - --form "rules[templateScreens][createMissing]=1" \ - --form "rules[templateLinkage][createMissing]=1" \ - --form "rules[applications][createMissing]=1" \ - --form "rules[items][updateExisting]=1" \ - --form "rules[items][createMissing]=1" \ - --form "rules[discoveryRules][updateExisting]=1" \ - --form "rules[discoveryRules][createMissing]=1" \ - --form "rules[triggers][updateExisting]=1" \ - --form "rules[triggers][createMissing]=1" \ - --form "rules[graphs][updateExisting]=1" \ - --form "rules[graphs][createMissing]=1" \ - --form "rules[httptests][updateExisting]=1" \ - --form "rules[httptests][createMissing]=1" \ - --form "rules[valueMaps][createMissing]=1" \ - --form "import=Import" \ - --form "backurl=templates.php" \ - --form "form_refresh=1" \ - --form "sid=${sid}" \ \ - "${zabbixFullpath}/conf.import.php?rules_preset=template" \ - | grep -c "Imported successfully") - - if [ "$importState" -eq "1" ];then - ynh_print_info "Template Yunohost imported !" - else - ynh_print_warn "Template Yunohost not imported !" - fi - - - #apply template to host - tokenapi=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{ "jsonrpc": "2.0","method": "user.login","params": {"user": "Admin","password": "zabbix"},"id": 1,"auth": null}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result') - zabbixHostID=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.get","params":{"filter":{"host":["Zabbix server"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].hostid') - zabbixTemplateID=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"template.get","params":{"filter":{"host":["Template Yunohost"]}},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result[0].templateid') - applyTemplate=$(curl -k -s --resolve $domain:443:127.0.0.1 --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","method":"host.massadd","params":{"hosts":[{"hostid":"'"$zabbixHostID"'"}],"templates":[{"templateid":"'"$zabbixTemplateID"'"}]},"auth":"'"$tokenapi"'","id":1}' "${zabbixFullpath}/api_jsonrpc.php" | jq -r '.result.hostids[]') - if [ "$applyTemplate" -eq "$zabbixHostID" ];then - ynh_print_info "Template Yunohost linked to Zabbix server !" - else - ynh_print_warn "Template Yunohost no linked to Zabbix server !" - fi -else - ynh_print_warn "Template Yunohost not imported ! (cannot connect admin)" -fi +import_template +#================================================= +# Link Yunohost template to the ZAbbix Server Host +#================================================= +link_template #================================================= # disable default admin #================================================= -ynh_print_info "disable default admin" disable_admin_user() #=================================================