Last active
January 31, 2024 01:03
-
-
Save scottames/0f5690c226154e0612bf to your computer and use it in GitHub Desktop.
Remote install splunk forwarder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# server to install / configure splunkforwarder on (required) | |
SERVER=$1 | |
# username to ssh with, default to current user (optional) | |
USERNAME=${2:-"$(id -u -n)"} | |
#NOTE: change the specifics of the function to match your environment, i.e. anything wrapped in <> | |
function install-splunk-forwarder () { | |
printf "installing splunkforwarder\n" | |
sudo mkdir -p "/opt/splunkforwarder/etc/apps/<CustomApp>/Client/local/" | |
sudo rpm -Uvh "splunkforwarder.rpm" | |
printf "running splunkforwarder for the first time\n" | |
sudo /opt/splunkforwarder/bin/splunk start --accept-license --answer-yes --auto-ports --no-prompt | |
printf "enabling splunkforwarder start on boot\n" | |
sudo /opt/splunkforwarder/bin/splunk enable boot-start | |
printf "changing the splunkforwarder admin password\n" | |
sudo /opt/splunkforwarder/bin/splunk edit user admin -password <PASSWORD> -auth admin:changeme | |
printf "writing conf file\n" | |
printf "[target-broker:deploymentServer]\ntargetUri = <splunk-indexer>:8089\n" | sudo tee "/opt/splunkforwarder/etc/apps/<CustomApp>/Client/local/deploymentclient.conf" | |
printf "resterting splunk service to apply conf\n" | |
sudo service splunk restart | |
rm -f "splunkforwarder.rpm" | |
} | |
scp splunkforwarder.rpm $USERNAME@$SERVER:~/ | |
ssh -t $USERNAME@$SERVER "$(declare -f install-splunk-forwarder);install-splunk-forwarder" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment