Merge branch 'master' of ssh://git.infini.ltd:64221/infini/console
This commit is contained in:
commit
49fcd1f8e9
|
@ -1,10 +1,10 @@
|
|||
package config
|
||||
|
||||
const LastCommitLog = "N/A"
|
||||
const BuildDate = "N/A"
|
||||
const LastCommitLog = "90dc208fb713ff5fab513c0d29e6ce26825b4395"
|
||||
const BuildDate = "2023-08-05T09:14:11Z"
|
||||
|
||||
const EOLDate = "N/A"
|
||||
const EOLDate = "2023-12-31T10:10:10Z"
|
||||
|
||||
const Version = "0.0.1-SNAPSHOT"
|
||||
const Version = "1.0.0_SNAPSHOT"
|
||||
|
||||
const BuildNumber = "001"
|
||||
|
|
|
@ -652,7 +652,7 @@ POST $[[INDEX_PREFIX]]channel/_doc/cgnb2nt3q95nmusjl65g
|
|||
},
|
||||
"method": "POST",
|
||||
"url": "{{$.env.SLACK_WEBHOOK_ENDPOINT}}",
|
||||
"body": "{\n \"blocks\": [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*{{if eq .priority \"critical\"}} :fire: {{else if eq .priority \"error\"}} :rotating_light: {{else}} :warning: {{end}} Incident <{{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}|#{{.event_id}}> is ongoing !*\\n :point_right: *{{.rule_name}} - {{.title}}*\"\n }\n },\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*TriggerAt:* {{.trigger_at | datetime}}\"\n }\n },\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*Priority:* {{.priority}}\"\n }\n },\n {\n \"type\": \"divider\"\n }\n ]\n {{if gt (len .results) 0}}\n ,\"attachments\": [\n {{range .results}}\n {\n \"color\": {{if eq .priority \"critical\"}} \"#C91010\" {{else if eq .priority \"error\"}} \"#EB4C21\" {{else}} \"#FFB449\" {{end}},\n \"blocks\": [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*Cluster:* <{{$.env.INFINI_CONSOLE_ENDPOINT}}/#/cluster/monitor/elasticsearch/{{ index .group_values 0}}|{{lookup \"category=metadata, object=cluster, property=name, default=N/A\" (index .group_values 0) }}>\"\n }\n }\n ]\n },\n {{end}}\n {\n \"blocks\": [\n {\n \"type\": \"divider\"\n },\n {\n \"type\": \"actions\",\n \"elements\": [\n {\n \"type\": \"button\",\n \"text\": {\n \"type\": \"plain_text\",\n \"text\": \"View Incident\" \n },\n \"url\": \"{{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}\"\n }\n ]\n },\n ]\n }\n ]\n {{end}}\n}"
|
||||
"body": "{\n \"blocks\": [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*{{if eq .priority \"critical\"}} :fire: {{else if eq .priority \"error\"}} :rotating_light: {{else}} :warning: {{end}} Incident <{{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}|#{{.event_id}}> is ongoing*\\n :point_right: *{{.rule_name}} - {{.title}}*\"\n }\n },\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*TriggerAt:* {{.trigger_at | datetime}}\"\n }\n },\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*Priority:* {{.priority}}\"\n }\n },\n {\n \"type\": \"divider\"\n }\n ]\n {{if gt (len .results) 0}}\n ,\"attachments\": [\n {{range .results}}\n {\n \"color\": {{if eq .priority \"critical\"}} \"#C91010\" {{else if eq .priority \"error\"}} \"#EB4C21\" {{else}} \"#FFB449\" {{end}},\n \"blocks\": [\n {\n \"type\": \"section\",\n \"text\": {\n \"type\": \"mrkdwn\",\n \"text\": \"*Cluster:* <{{$.env.INFINI_CONSOLE_ENDPOINT}}/#/cluster/monitor/elasticsearch/{{ index .group_values 0}}|{{lookup \"category=metadata, object=cluster, property=name, default=N/A\" (index .group_values 0) }}>\"\n }\n }\n ]\n },\n {{end}}\n {\n \"blocks\": [\n {\n \"type\": \"divider\"\n },\n {\n \"type\": \"actions\",\n \"elements\": [\n {\n \"type\": \"button\",\n \"text\": {\n \"type\": \"plain_text\",\n \"text\": \"View Incident\" \n },\n \"url\": \"{{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}\"\n }\n ]\n },\n ]\n }\n ]\n {{end}}\n}"
|
||||
},
|
||||
"sub_type": "slack",
|
||||
"enabled": false
|
||||
|
@ -688,7 +688,7 @@ POST $[[INDEX_PREFIX]]channel/_doc/cgiospt3q95q49k3u00g
|
|||
},
|
||||
"method": "POST",
|
||||
"url": "{{$.env.DINGTALK_WEBHOOK_ENDPOINT}}",
|
||||
"body": "{\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"title\": \"{{.title}}\",\n \"text\": \"\\n\\n🔥 **{{.title}}**\\n\\nIncident [{{.event_id}}]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}) is ongoing !\\n\\nPriority: {{.priority}}\\n\\nEventID: {{.event_id}}\\n\\nTarget: {{.resource_name}}-{{.objects}}\\n\\nTriggerAt: {{.trigger_at | datetime}}\\n\\n---\\n\\n{{.message}}\"\n }\n}"
|
||||
"body": "{\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"title\": \"{{.title}}\",\n \"text\": \"\\n\\n🔥 **{{.title}}**\\n\\nIncident [{{.event_id}}]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}) is ongoing\\n\\nPriority: {{.priority}}\\n\\nEventID: {{.event_id}}\\n\\nTarget: {{.resource_name}}-{{.objects}}\\n\\nTriggerAt: {{.trigger_at | datetime}}\\n\\n---\\n\\n{{.message}}\"\n }\n}"
|
||||
},
|
||||
"sub_type": "dingtalk",
|
||||
"enabled": false
|
||||
|
@ -726,7 +726,7 @@ POST $[[INDEX_PREFIX]]channel/_doc/ch1os6t3q95lk6lepkq0
|
|||
},
|
||||
"method": "POST",
|
||||
"url": "{{$.env.FEISHU_WEBHOOK_ENDPOINT}}",
|
||||
"body": "{\n \"msg_type\": \"interactive\",\n \"card\": {\n \"header\": {\n \"title\": {\n \"content\": \"[ INFINI Platform Alerting ]\",\n \"tag\": \"plain_text\"\n },\n \"template\":\"{{if eq .priority \"critical\"}}red{{else if eq .priority \"high\"}}orange{{else if eq .priority \"medium\"}}yellow{{else if eq .priority \"low\"}}grey{{else}}blue{{end}}\"\n },\n \"elements\": [{\n \"tag\": \"markdown\",\n \"content\": \"🔥 Incident [#{{.event_id}}]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}) is ongoing ! \\n **{{.title}}**\\nPriority: {{.priority}}\\nEventID: {{.event_id}}\\nTarget: {{.resource_name}}-{{.objects}}\\nTriggerAt: {{.trigger_at | datetime}}\"\n },{\n \"tag\": \"hr\"\n },\n {\n \"tag\": \"markdown\",\n \"content\": \"{{ .message | str_replace \"\\n\" \"\\\\n\" }}\"\n }\n ]\n}\n}"
|
||||
"body": "{\n \"msg_type\": \"interactive\",\n \"card\": {\n \"header\": {\n \"title\": {\n \"content\": \"[ INFINI Platform Alerting ]\",\n \"tag\": \"plain_text\"\n },\n \"template\":\"{{if eq .priority \"critical\"}}red{{else if eq .priority \"high\"}}orange{{else if eq .priority \"medium\"}}yellow{{else if eq .priority \"low\"}}grey{{else}}blue{{end}}\"\n },\n \"elements\": [{\n \"tag\": \"markdown\",\n \"content\": \"🔥 Incident [#{{.event_id}}]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}) is ongoing\\n **{{.title}}**\\nPriority: {{.priority}}\\nEventID: {{.event_id}}\\nTarget: {{.resource_name}}-{{.objects}}\\nTriggerAt: {{.trigger_at | datetime}}\"\n },{\n \"tag\": \"hr\"\n },\n {\n \"tag\": \"markdown\",\n \"content\": \"{{ .message | str_replace \"\\n\" \"\\\\n\" }}\"\n }\n ]\n}\n}"
|
||||
},
|
||||
"sub_type": "feishu",
|
||||
"enabled": false
|
||||
|
@ -762,7 +762,7 @@ POST $[[INDEX_PREFIX]]channel/_doc/cj8ctat3q95l9ebbntlg
|
|||
},
|
||||
"method": "POST",
|
||||
"url": "{{$.env.DINGTALK_WEBHOOK_ENDPOINT}}",
|
||||
"body": "{\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"title\": \"{{.title}}\",\n \"text\": \"\\n\\n🌈 **{{.title}}**\\n\\n{{.message}}\\n\\n> [View Incident]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}})\"\n }\n}\n"
|
||||
"body": "{\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"title\": \"{{.title}}\",\n \"text\": \"\\n\\n🌈 **{{.title}}**\\n\\n{{.message}}\\n\\n---\\n\\n> [View Incident]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}})\"\n }\n}\n"
|
||||
},
|
||||
"sub_type": "dingtalk",
|
||||
"enabled": false
|
||||
|
@ -780,7 +780,7 @@ POST $[[INDEX_PREFIX]]channel/_doc/cgnb2kt3q95nmusjl64g
|
|||
},
|
||||
"method": "POST",
|
||||
"url": "{{$.env.WECOM_WEBHOOK_ENDPOINT}}",
|
||||
"body": "{\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": \"**[ INFINI Platform Alerting ]**\\n🔥 Incident [#{{.event_id}}]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}) is ongoing !\\n**{{.title}}**\\nPriority: {{.priority}}\\n\\nEventID: {{.event_id}}\\n\\nTarget: {{.resource_name}}-{{.objects}}\\n\\nTriggerAt: {{.trigger_at | datetime}}\\n{{.message}}\"\n }\n}"
|
||||
"body": "{\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": \"**[ INFINI Platform Alerting ]**\\n🔥 Incident [#{{.event_id}}]({{$.env.INFINI_CONSOLE_ENDPOINT}}/#/alerting/alert/{{.event_id}}) is ongoing\\n**{{.title}}**\\n>Priority: {{.priority}}\\n\\n>EventID: {{.event_id}}\\n\\n>Target: {{.resource_name}}-{{.objects}}\\n\\n>TriggerAt: {{.trigger_at | datetime}}\\n\\n{{.message}}\"\n }\n}"
|
||||
},
|
||||
"sub_type": "wechat",
|
||||
"enabled": false
|
||||
|
|
|
@ -1,184 +1,222 @@
|
|||
#!/bin/bash
|
||||
# Agent install script for UNIX-like OS
|
||||
# Author: INFINI
|
||||
# BASE_URL : need, download server address,eg: https://release.infinilabs.com/agent/stable
|
||||
# AGENT_VER : need, Agent version, eg: 0.4.0-126
|
||||
# INSTALL_PATH : option, download path. eg: /home/user/infini default: /opt
|
||||
# ES_NAME
|
||||
# ES_PWD
|
||||
#!/usr/bin/env bash
|
||||
|
||||
printf "\n* _ ___ __ __ _____ "
|
||||
printf "\n* /_\\ / _ \\ /__\\/\\ \\ \\/__ \\"
|
||||
printf "\n* //_\\\\ / /_\\//_\\ / \\/ / / /\\/"
|
||||
printf "\n* / _ \\/ /_\\\\//__/ /\\ / / / "
|
||||
printf "\n* \\_/ \\_/\\____/\\__/\\_\\ \\/ \\/ \n\n"
|
||||
# detect root user
|
||||
if [ "$(echo "$UID")" = "0" ]; then
|
||||
sudo_cmd=''
|
||||
else
|
||||
sudo_cmd='sudo'
|
||||
set -eo pipefail
|
||||
|
||||
function print_usage() {
|
||||
echo "Usage: curl -sSL http://get.infini.sh/agent.html | sudo bash -s -- [-u url_for_download_program] [-v version_for_program ] [-t taget_install_dir] [-p prot_for_program]"
|
||||
echo "Options:"
|
||||
echo " -u, --url <url> Download url of the program to install which default is http://localhost"
|
||||
echo " -v, --version <version> Version of the program to install which default is latest from "
|
||||
echo " -t, --target <dir> Target directory of the program install which default is /opt/agent"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function print_header() {
|
||||
echo " "
|
||||
echo " @@@@@@@@@@@"
|
||||
echo " @@@@@@@@@@@@"
|
||||
echo " @@@@@@@@@@@@"
|
||||
echo " @@@@@@@@@&@@@"
|
||||
echo " #@@@@@@@@@@@@@"
|
||||
echo " @@@ @@@@@@@@@@@@@ "
|
||||
echo " &@@@@@@@ &@@@@@@@@@@@@@ "
|
||||
echo " @&@@@@@@@&@ @@@&@@@@@@@&@ "
|
||||
echo " @@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@ "
|
||||
echo " @@@@@@@@@@@@@@@@@@& @@@@@@@@@@@@@ "
|
||||
echo " %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ "
|
||||
echo " @@@@@@@@@@@@&@@@@@@@@@@@@@@@ "
|
||||
echo " @@ ,@@@@@@@@@@@@@@@@@@@@@@@& "
|
||||
echo " @@@@@. @@@@@&@@@@@@@@@@@@@@ "
|
||||
echo " @@@@@@@@@@ @@@@@@@@@@@@@@@# "
|
||||
echo " @&@@@&@@@&@@@ &@&@@@&@@@&@ "
|
||||
echo " @@@@@@@@@@@@@. @@@@@@@* "
|
||||
echo " @@@@@@@@@@@@@ %@@@ "
|
||||
echo " @@@@@@@@@@@@@ "
|
||||
echo "/@@@@@@@&@@@@@ "
|
||||
echo "@@@@@@@@@@@@@ "
|
||||
echo "@@@@@@@@@@@@@ "
|
||||
echo "@@@@@@@@@@@@ Welcome to INFINI Labs!"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "Now attempting the installation... "
|
||||
echo ""
|
||||
}
|
||||
|
||||
function print_footprint() {
|
||||
echo " __ _ __ ____ __ _ __ __ "
|
||||
echo " / // |/ // __// // |/ // / "
|
||||
echo " / // || // _/ / // || // / "
|
||||
echo "/_//_/|_//_/ /_//_/|_//_/ "
|
||||
echo ""
|
||||
echo "©INFINI.LTD, All Rights Reserved."
|
||||
echo ""
|
||||
}
|
||||
|
||||
__try() {
|
||||
if [[ $try_status -eq 0 ]]; then
|
||||
! exception=$( $@ 2>&1 >/dev/null )
|
||||
try_status=${PIPESTATUS[0]}
|
||||
fi
|
||||
}
|
||||
|
||||
__catch() {
|
||||
_old_try=$try_status
|
||||
try_status=0
|
||||
[[ $_old_try -ne 0 ]]
|
||||
}
|
||||
|
||||
function get_latest_version() {
|
||||
echo $(curl -m3 -s "https://release.infinilabs.com/.latest" |sed 's/",/"/;s/"//g;s/://1' |grep -Ev '^[{}]' |grep "$program_name" |awk '{print $NF}')
|
||||
}
|
||||
|
||||
function check_dir() {
|
||||
if [[ ! -d "${install_dir}" ]]; then
|
||||
__try mkdir -p "${install_dir}"
|
||||
if __catch e; then
|
||||
echo -e "Error: Unable to create installation directory, please manually create and reinstall.\nsudo mkdir -p ${install_dir} && sudo chown -R \$(whoami) ${install_dir}" >&2; exit 1;
|
||||
fi
|
||||
fi
|
||||
|
||||
##################
|
||||
# colors
|
||||
##################
|
||||
RED="\033[31m"
|
||||
CLR="\033[0m"
|
||||
GREEN="\033[32m"
|
||||
owner=$(ls -ld "${install_dir}" |awk '{print $3}')
|
||||
if [[ "${owner}" != "$(whoami)" ]]; then
|
||||
echo -e "Error: The installation directory ${install_dir} should be owner by current user.\nsudo chown -R \$(whoami) ${install_dir}" >&2; exit 1;
|
||||
fi
|
||||
|
||||
##################
|
||||
# validate os & arch
|
||||
##################
|
||||
#if [[ "$(ls -A ${install_dir})" ]]; then
|
||||
# echo "Error: The installation directory ${install_dir} should be clean." >&2; exit 1;
|
||||
#fi
|
||||
}
|
||||
|
||||
arch=
|
||||
case $(uname -m) in
|
||||
function check_platform() {
|
||||
local platform=$(uname)
|
||||
local arch=$(uname -m)
|
||||
|
||||
"x86_64")
|
||||
arch="amd64"
|
||||
case $platform in
|
||||
"Linux")
|
||||
case $arch in
|
||||
"i386"|"i686"|"x86")
|
||||
file_ext="linux-386.tar.gz"
|
||||
;;
|
||||
|
||||
"i386" | "i686")
|
||||
arch="386"
|
||||
"x86_64"|"amd64")
|
||||
file_ext="linux-amd64.tar.gz"
|
||||
;;
|
||||
|
||||
"aarch64")
|
||||
arch="arm64"
|
||||
"aarch64"|"arm64")
|
||||
file_ext="linux-arm64.tar.gz"
|
||||
;;
|
||||
|
||||
"arm" | "armv7l")
|
||||
arch="arm"
|
||||
"armv5tel")
|
||||
file_ext="linux-armv5.tar.gz"
|
||||
;;
|
||||
|
||||
"arm64")
|
||||
arch="arm64"
|
||||
"armv6l")
|
||||
file_ext="linux-armv6.tar.gz"
|
||||
;;
|
||||
"armv7"|"armv7l")
|
||||
file_ext="linux-armv7.tar.gz"
|
||||
;;
|
||||
"mips"|"mipsel")
|
||||
file_ext="linux-mips.tar.gz"
|
||||
;;
|
||||
"mips64")
|
||||
file_ext="linux-mips64.tar.gz"
|
||||
;;
|
||||
"mips64el")
|
||||
file_ext="linux-mips64le.tar.gz"
|
||||
;;
|
||||
"loong64")
|
||||
file_ext="linux-loong64.tar.gz"
|
||||
;;
|
||||
"sw_64")
|
||||
file_ext="linux-sw64.tar.gz"
|
||||
;;
|
||||
"riscv64")
|
||||
file_ext="linux-riscv64.tar.gz"
|
||||
;;
|
||||
|
||||
*)
|
||||
# shellcheck disable=SC2059
|
||||
printf "${RED}[E] Unsupport arch $(uname -m) ${CLR}\n"
|
||||
echo "Unsupported architecture: ${arch}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"Darwin")
|
||||
case $arch in
|
||||
"x86_64"|"amd64")
|
||||
file_ext="mac-amd64.zip"
|
||||
;;
|
||||
"arm64")
|
||||
file_ext="mac-arm64.zip"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: ${arch}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
"MINGW"*|"WSL"*|"Cygwin")
|
||||
case $arch in
|
||||
"i386"|"i686")
|
||||
file_ext="windows-386.zip"
|
||||
;;
|
||||
"x86_64"|"amd64")
|
||||
file_ext="windows-amd64.zip"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: ${arch}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported platform: ${platform}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
os="linux"
|
||||
function install_binary() {
|
||||
local download_url="$location/${program_name}-${version}-${file_ext}"
|
||||
echo "File: [$download_url]"
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
if [[ $arch != "amd64" ]] && [[ $arch != "arm64" ]]; then # Darwin only support amd64 and arm64
|
||||
# shellcheck disable=SC2059
|
||||
printf "${RED}[E] Darwin only support amd64/arm64.${CLR}\n"
|
||||
exit 1;
|
||||
tmp_dir="$(mktemp -d)"
|
||||
cd "$tmp_dir"
|
||||
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -# -LO "$download_url"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -q -nc --show-progress --progress=bar:force:noscroll "$download_url"
|
||||
else
|
||||
echo "Error: Could not find curl or wget, Please install wget or curl in advance." >&2; exit 1;
|
||||
fi
|
||||
|
||||
os="mac"
|
||||
|
||||
# # NOTE: under darwin, for arm64 and amd64, both use amd64
|
||||
# arch="arm"
|
||||
if [[ "${file_ext}" == *".tar.gz" ]]; then
|
||||
tar -xzf "${program_name}-${version}-${file_ext}" -C "$install_dir"
|
||||
else
|
||||
unzip -q "${program_name}-${version}-${file_ext}" -d "$install_dir"
|
||||
fi
|
||||
|
||||
##################
|
||||
# validate params
|
||||
##################
|
||||
|
||||
base_url="{{base_url}}"
|
||||
if [ -n "$BASE_URL" ]; then
|
||||
base_url=$BASE_URL
|
||||
fi
|
||||
|
||||
agent_ver="{{agent_version}}"
|
||||
if [ -n "$AGENT_VER" ]; then
|
||||
agent_ver=$AGENT_VER
|
||||
fi
|
||||
cd "${install_dir}" && rm -rf "${tmp_dir}"
|
||||
}
|
||||
|
||||
function install_certs() {
|
||||
ca_crt="{{ca_crt}}"
|
||||
client_crt="{{client_crt}}"
|
||||
client_key="{{client_key}}"
|
||||
|
||||
##################
|
||||
# download agent
|
||||
##################
|
||||
mkdir -p ${install_dir}/config
|
||||
echo -e "${ca_crt}" > ${install_dir}/config/ca.crt
|
||||
echo -e "${client_crt}" > ${install_dir}/config/client.crt
|
||||
echo -e "${client_key}" > ${install_dir}/config/client.key
|
||||
}
|
||||
|
||||
suffix="tar.gz"
|
||||
if [[ "$os" == "mac" ]]; then
|
||||
suffix="zip"
|
||||
fi
|
||||
|
||||
download_url="${base_url}/agent-${agent_ver}-${os}-${arch}.${suffix}"
|
||||
|
||||
install_path="/opt"
|
||||
if [ -n "$INSTALL_PATH" ]; then
|
||||
install_path=$INSTALL_PATH
|
||||
fi
|
||||
|
||||
file_name="agent-${agent_ver}-${os}-${arch}.${suffix}" #agent在服务器上的文件名
|
||||
agent="${install_path}/agent/${file_name}" #agent下载后保存的文件
|
||||
agent_exc="${install_path}/agent/agent-${os}-${arch}" #agent可执行文件
|
||||
|
||||
agent_exsit="true"
|
||||
if [ ! -d "${install_path}/agent" ]; then
|
||||
printf "\n* mkdir -p ${install_path}/agent"
|
||||
$sudo_cmd mkdir -p "${install_path}/agent"
|
||||
agent_exsit="false"
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "\n* downloading ${download_url}\n"
|
||||
|
||||
printf "\n* save to : ${agent}\n"
|
||||
|
||||
cd "$install_path/agent"
|
||||
|
||||
sudo curl -O --progress-bar $download_url
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "\n* downloaded: ${agent}"
|
||||
|
||||
##################
|
||||
# install agent
|
||||
##################
|
||||
|
||||
printf "\n* start install"
|
||||
|
||||
if [[ "${suffix}" == "zip" ]]; then
|
||||
printf "\n* uzip ${agent}\n"
|
||||
$sudo_cmd unzip $agent
|
||||
else
|
||||
printf "\n* tar -xzvf ${agent}\n"
|
||||
$sudo_cmd tar -xzvf $agent
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -f ${agent}
|
||||
|
||||
##################
|
||||
# save cert
|
||||
##################
|
||||
$sudo_cmd mkdir -p config
|
||||
$sudo_cmd sh -c "echo '${ca_crt}' > ./config/ca.crt"
|
||||
$sudo_cmd sh -c "echo '${client_crt}' > ./config/client.crt"
|
||||
$sudo_cmd sh -c "echo '${client_key}' > ./config/client.key"
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
port="{{port}}"
|
||||
|
||||
## generate agent.yml
|
||||
agent_config="path.configs: "config"
|
||||
function install_config() {
|
||||
port={{port}}
|
||||
cat <<EOF > ${install_dir}/agent.yml
|
||||
configs.auto_reload: true
|
||||
|
||||
env:
|
||||
API_BINDING: "0.0.0.0:${port}"
|
||||
|
||||
path.data: data
|
||||
path.logs: log
|
||||
path.configs: config
|
||||
|
||||
api:
|
||||
enabled: true
|
||||
|
@ -198,56 +236,76 @@ badger:
|
|||
|
||||
agent:
|
||||
major_ip_pattern: ".*"
|
||||
"
|
||||
EOF
|
||||
}
|
||||
|
||||
agent_yml_path="${install_path}/agent/agent.yml"
|
||||
function install_service() {
|
||||
agent_svc=${install_dir}/${program_name}-${file_ext%%.*}
|
||||
chmod 755 $agent_svc
|
||||
|
||||
$sudo_cmd rm $agent_yml_path
|
||||
$sudo_cmd touch $agent_yml_path
|
||||
$sudo_cmd sh -c "echo '${agent_config}' > $agent_yml_path"
|
||||
macos_svc=/Library/LaunchDaemons/agent.plist
|
||||
linux_svc=/etc/systemd/system/agent.service
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
if [[ -f "$linux_svc" || -f "$macos_svc" ]]; then
|
||||
echo "[agent] waiting service stop & uninstall for existing agent"
|
||||
$agent_svc -service stop &>/dev/null
|
||||
$agent_svc -service uninstall &>/dev/null
|
||||
fi
|
||||
|
||||
$sudo_cmd chmod +x $agent_exc
|
||||
echo "[agent] waiting service install & start"
|
||||
$agent_svc -service install &>/dev/null
|
||||
$agent_svc -service start &>/dev/null
|
||||
|
||||
#try to stop and uninstall service
|
||||
macos=/Library/LaunchDaemons/agent.plist
|
||||
linux=/etc/systemd/system/agent.service
|
||||
if [[ -f "$linux" || -f "$macos" ]]; then
|
||||
printf "\n* stop && uninstall service\n"
|
||||
$sudo_cmd $agent_exc -service stop &>/dev/null
|
||||
$sudo_cmd $agent_exc -service uninstall &>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
printf "\n* start install service\n"
|
||||
$sudo_cmd $agent_exc -service install
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "\n* service installed\n"
|
||||
printf "\n* service starting >>>>>>\n"
|
||||
$sudo_cmd $agent_exc -service start
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "\n* agent service started"
|
||||
console_endpoint="{{console_endpoint}}"
|
||||
sleep 3
|
||||
printf "\n* start register\n"
|
||||
function register_agent() {
|
||||
token={{token}}
|
||||
curl -X POST ${console_endpoint}/agent/instance?token=${token}
|
||||
console_endpoint="{{console_endpoint}}"
|
||||
echo "[agent] waiting registering to INFINI Console"
|
||||
__try curl -s --retry 5 --retry-delay 3 -m30 -XPOST -o /dev/null ${console_endpoint}/agent/instance?token=${token}
|
||||
}
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
function main() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-u|--url) location="$2"; shift 2 ;;
|
||||
-v|--version) version="$2"; shift 2 ;;
|
||||
-t|--target) target_dir="$2"; shift 2 ;;
|
||||
*) print_usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
program_name=agent
|
||||
install_dir=${target_dir:-/opt/$program_name}
|
||||
latest_version=$(get_latest_version)
|
||||
version=${version:-$latest_version}
|
||||
file_ext=""
|
||||
|
||||
if [[ -z "${version}" ]]; then
|
||||
echo "Error: Could not obtain the latest version number. Please check the network and try again.">&2; exit 1;
|
||||
else
|
||||
echo "Name: [${program_name}], Version: [${version}], Path: [${install_dir}]]"
|
||||
fi
|
||||
printf "\n* agent registered\n"
|
||||
|
||||
printf "\n* ${GREEN}Congratulations, install success!${CLR}\n\n"
|
||||
check_dir
|
||||
check_platform
|
||||
install_binary
|
||||
install_certs
|
||||
install_config
|
||||
install_service
|
||||
register_agent
|
||||
|
||||
echo ""
|
||||
echo ""
|
||||
echo "----------------------------------------------------------------"
|
||||
echo "Congratulations, agent install success!"
|
||||
echo "----------------------------------------------------------------"
|
||||
echo ""
|
||||
echo ""
|
||||
|
||||
print_footprint
|
||||
}
|
||||
|
||||
print_header
|
||||
|
||||
main "$@"
|
||||
|
|
Loading…
Reference in New Issue