Contexte :

Script qui permet de collecter des informations sur une machine sur laquelle un service Splunk est installé (Core ou Forwarder).
Cette collecte utilise des commandes CLI Splunk, API Splunk ou CLI système.

Script :

Récupération :

Aller à l'URL : Github Splunk ShowMe .

Utilisation :

Aide :

 1 $ ./splunk_showme.sh -h
 2 
 3 Usage : splunk_showme.sh [-e] [-i] [-h] [-D] [-v] [-o <output file>]
 4 
 5    -e : Execute script
 6    -i : Display commands informations
 7    -h : Help
 8    -D : Debug script
 9    -o : Write output in a file
10    -v : Display version
11 
12 Note :
13 Splunk URL based on : https://docs.splunk.com/Documentation/Splunk/latest/RESTREF/RESTintrospect
14 Splunk CLI based on : https://docs.splunk.com/Documentation/Splunk/latest/Admin/CLIadmincommands (list, show and display without arg)

Information :

Enumération de toutes les commandes :

 1 $ ./splunk_showme.sh -i
 2 0 - Display Splunk Version - SPLUNKCLI - splunk version
 3 1 - Display Splunk monitor - SPLUNKCLI - splunk list monitor
 4 2 - Display Splunk GUID - CLI - /bin/cat /opt/splunk/etc/instance.cfg
 5 3 - Display Splunk servername - SPLUNKCLI - splunk show servername
 6 4 - Display Splunk default-hostname - SPLUNKCLI - splunk show default-hostname
 7 5 - Display Splunk minfreemb (Free space in Mb to SPLUNKHOME) - SPLUNKCLI - splunk show minfreemb
 8 6 - Display Splunk boot-start - SPLUNKCLI - splunk display boot-start
 9 7 - Display Splunkd port - SPLUNKCLI - splunk show splunkd-port
10 8 - Display Splunk web port - SPLUNKCLI - splunk show web-port
11 9 - Display Splunk kvstore port - SPLUNKCLI - splunk show kvstore-port
12 10 - Display Splunk cluster-bundle-status - SPLUNKCLI - splunk show cluster-bundle-status
13 11 - Display Splunk datastore-dir - SPLUNKCLI - splunk show datastore-dir
14 ......
15 90 - Display kernel informations - CLI - /bin/uname -a
16 91 - Display short disk information - CLI - /bin/df -Th
17 92 - EXECUTE ALL COMMANDS - ALL -
18 93 - EXIT SCRIPT - QUIT -

Execution :

 1 $ ./splunk_showme.sh -e
 2 0 - Display Splunk Version
 3 1 - Display Splunk monitor
 4 2 - Display Splunk GUID
 5 3 - Display Splunk servername
 6 ....
 7 91 - Display short disk information
 8 92 - EXECUTE ALL COMMANDS
 9 93 - EXIT SCRIPT
10 
11 
12 
13 Command number to execute ? 17
14 Splunk user : admin
15 Splunk password :
16 
17 
18 Command choice : Display Splunkd status
19   Command execution : splunk status splunkd
20   Output :
21 
22 splunkd is running (PID: 1332).
23 splunk helpers are running (PIDs: 1336 1350 1506 1562).

Possibilité de lancer toutes les commandes, dans la version 0.1 via le choix 92.
En ajoutant l'option -o outputfile.log permet de sauvegarder dans un fichier la sortie des commandes (sans les entrées claviers).

Ajout de commandes :

Il y a 3 types de commandes :

  • SPLUNKCLI : commande Splunk : $SPLUNK_HOME/bin/splunk ...
  • SPLUNKURL : API local Splunk : https://127.0.0.1:8089/...
  • CLI : Commande système/OS

Syntaxe du bloque à ajouter :

  • indice 0 : Description courte de la commande
  • indice 1 : Commande ou URL
  • indice 2 : Type de commande : CLI/SPLUNKCLI/SPLUNKURL
  • indice 3 : Demande d'authentication : 0=No 1=Yes

SPLUNKCLI :

Bloque à ajouter :

1 arr[0,"${index}"]="Display Splunk ......."
2 arr[1,"${index}"]="splunk ....."
3 arr[2,"${index}"]="SPLUNKCLI"
4 arr[3,"${index}"]="1"
5 let "index++"

Indice 1, chemin par défaut : $SPLUNK_HOME/bin/.
Note : commande sans argument.

SPLUNKURL :

Bloque à ajouter :

1 arr[0,"${index}"]="Get desc......"
2 arr[1,"${index}"]="/URI/PATH"
3 arr[2,"${index}"]="SPLUNKURL"
4 arr[3,"${index}"]="1"
5 let "index++"

Indice 1, ajout de l'URI (aprés https://127.0.0.1:8089/).

CLI :

Bloque à ajouter :

1 arr[0,"${index}"]="Command informations"
2 arr[1,"${index}"]="BINARY_PATH with option"
3 arr[2,"${index}"]="CLI"
4 arr[3,"${index}"]="0"
5 let "index++"

Commande sans authentication.

Annexes :

Doc officielle Splunk - REST Introspec
Doc officielle Splunk - Splunk cli commands