Skip to content

Commit

Permalink
Merge pull request #415 from jmpsec/remove-metrics-provision
Browse files Browse the repository at this point in the history
Removing metrics from the provision script
  • Loading branch information
javuto authored Mar 9, 2024
2 parents 358efdc + b3548a1 commit c964519
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 83 deletions.
63 changes: 2 additions & 61 deletions deploy/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function _log() {

# Update packages
function package_repo_update() {
if [[ "$DISTRO" == "ubuntu" ]]; then
if [[ "$DISTRO" == "ubuntu" || "$DISTRO" == "debian" ]]; then
log "Running apt-get update"
sudo DEBIAN_FRONTEND=noninteractive apt-get update
elif [[ "$DISTRO" == "centos" ]]; then
Expand All @@ -30,7 +30,7 @@ function package_repo_update() {
# Install a package in the system
# string package_name
function package() {
if [[ "$DISTRO" == "ubuntu" ]]; then
if [[ "$DISTRO" == "ubuntu" || "$DISTRO" == "debian" ]]; then
INSTALLED=`dpkg-query -W -f='${Status} ${Version}\n' "$1" || true`
if [[ -n "$INSTALLED" && ! "$INSTALLED" = *"unknown ok not-installed"* ]]; then
log "$1 is already installed. skipping."
Expand Down Expand Up @@ -386,18 +386,6 @@ function configure_redis() {
sudo systemctl enable "$__service"
}

# Customize the MOTD in Ubuntu
# string path_to_motd_script
function set_motd_ubuntu() {
local __motd=$1

# If the cloudguest MOTD exists, disable it
if [[ -f /etc/update-motd.d/51/cloudguest ]]; then
sudo chmod -x /etc/update-motd.d/51-cloudguest
fi
sudo cp "$__motd" /etc/update-motd.d/10-help-text
}

# Customize the MOTD in CentOS
# string path_to_motd_script
function set_motd_centos() {
Expand Down Expand Up @@ -427,50 +415,3 @@ function install_go_21() {
go version
fi
}

# Install Grafana 6.7.4 in Ubuntu
function install_grafana() {
local __version="6.7.4"
local __file="grafana_${__version}_amd64.deb"

log "Installing Grafana $__version dependencies"
package adduser
package libfontconfig
log "Downloading Grafana $__version package"
wget "https://dl.grafana.com/oss/release/$__file" -O "/tmp/grafana_${__version}_amd64.deb"
sudo dpkg -i "/tmp/grafana_${__version}_amd64.deb"
}

# Configure Grafana service in Ubuntu
function configure_grafana() {
log "Reloading systemd manager configuration"
sudo systemctl daemon-reload
log "Enabling Grafana service"
sudo systemctl enable grafana-server
log "Starting grafana-server"
sudo systemctl start grafana-server
}

# Install InfluxDB and Telegraf in Ubuntu
function install_influx_telegraf() {
local __repo="/etc/apt/sources.list.d/influxdb.list"
log "Adding InfluxDB+Telegraf repository"
if [[ ! -f "$__repo" ]]; then
echo "deb https://repos.influxdata.com/ubuntu bionic stable" | sudo tee "$__repo"
fi
log "Import apt key"
sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
sudo apt-get update
package influxdb
package telegraf
}

# Configure InfluxDB and Telegraf in Ubuntu
function configure_influx_telegraf() {
log "Enabling and starting InfluxDB service"
sudo systemctl enable influxdb
sudo systemctl start influxdb
log "Enabling and starting Telegraf service"
sudo systemctl enable telegraf
sudo systemctl start telegraf
}
23 changes: 1 addition & 22 deletions deploy/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
# -S PATH --dest PATH Path to binaries. Default is /opt/osctrl
# -n --nginx Install and configure nginx as TLS termination
# -P --postgres Install and configure PostgreSQL as backend
# -M --metrics Install and configure all services for metrics (InfluxDB + Telegraf + Grafana)
# -R --redis Install and configure Redis as cache
# -E --enroll Enroll the serve into itself using osquery. Default is disabled
# -N NAME --env NAME Initial environment name to be created. Default is the mode (dev or prod)
Expand Down Expand Up @@ -117,7 +116,6 @@ function usage() {
printf " -S PATH --dest PATH \tPath to binaries. Default is /opt/osctrl\n"
printf " -n --nginx \t\tInstall and configure nginx as TLS termination\n"
printf " -P --postgres \tInstall and configure PostgreSQL as backend\n"
printf " -M --metrics \tInstall and configure all services for metrics (InfluxDB + Telegraf + Grafana)\n"
printf " -R --redis \t\tInstall and configure Redis as cache\n"
printf " -E --enroll \tEnroll the serve into itself using osquery. Default is disabled\n"
printf " -N NAME --env NAME \tInitial environment name to be created. Default is the mode (dev or prod)\n"
Expand Down Expand Up @@ -164,7 +162,6 @@ KEYFILE=""
CERTFILE=""
DOMAIN=""
EMAIL=""
METRICS=false
ENROLL=false
UPDATE=false
NGINX=false
Expand Down Expand Up @@ -227,7 +224,7 @@ VALID_TYPE=("self" "own" "certbot")
VALID_PART=("$TLS_COMPONENT" "$ADMIN_COMPONENT" "$API_COMPONENT" "all")

# Extract arguments
ARGS=$(getopt -n "$0" -o hm:t:p:PRk:nMEUc:d:e:s:S:X: -l "help,mode:,type:,part:,public-tls-port:,private-tls-port:,public-admin-port:,private-admin-port:,public-api-port:,private-api-port:,all-hostname:,tls-hostname:,admin-hostname:,api-hostname:,keyfile:,nginx,postgres,redis,metrics,enroll,upgrade,certfile:,domain:,email:,source:,dest:,password:" -- "$@")
ARGS=$(getopt -n "$0" -o hm:t:p:PRk:nEUc:d:e:s:S:X: -l "help,mode:,type:,part:,public-tls-port:,private-tls-port:,public-admin-port:,private-admin-port:,public-api-port:,private-api-port:,all-hostname:,tls-hostname:,admin-hostname:,api-hostname:,keyfile:,nginx,postgres,redis,enroll,upgrade,certfile:,domain:,email:,source:,dest:,password:" -- "$@")

if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi

Expand Down Expand Up @@ -344,11 +341,6 @@ while true; do
REDIS=true
shift
;;
-M|--metrics)
SHOW_USAGE=false
METRICS=true
shift
;;
-E|--enroll)
SHOW_USAGE=false
ENROLL=true
Expand Down Expand Up @@ -670,19 +662,6 @@ else
configure_redis "$REDIS_CONF" "$REDIS_SERVICE" "$REDIS_ETC" "$_CACHE_PASS"
fi

# Metrics - InfluxDB + Telegraf + Grafana
if [[ "$METRICS" == true ]]; then
if [[ "$DISTRO" == "ubuntu" || "$DISTRO" == "debian" ]]; then
install_influx_telegraf
configure_influx_telegraf
install_grafana
configure_grafana
elif [[ "$DISTRO" == "centos" ]]; then
log "Not ready yet to install metrics for CentOS"
exit $OHNOES
fi
fi

# Prepare destination and configuration folder
sudo mkdir -p "$DEST_PATH/config"

Expand Down

0 comments on commit c964519

Please sign in to comment.