SECTOR NORD AG Tipp des Monats
[SNAG-View] CLI - Massenänderung
Wie ändere ich Objekte?
Serviceprofile:
svcli value:set --id <id> svobjects name <neuerName> svcli value:set --id 44895 svobjects name SP_test1234 |
Service:
svcli value:set --id <id> nagios serviceDescription <neuerName> svcli value:set --id 18783 nagios serviceDescription S_00bvd |
Host:
svcli value:set --id <id> nagios hostName <neuerName> svcli value:set --id 126251 nagios hostName Test |
Die passende ID kann über "entity:list" ermittelt werden:
svcli entity:list sv_service
svcli entity:list sv_host
svcli entity:list sv_service_profile
Hier ist ein kleines Beispiel Script zum Anpassen:
./rename.sh -i svprofile -s 's/E2EE/E2E/' |
rename.sh
#!/bin/bash function helpFunction { echo "" echo "Usage: $0 -i import -b parameterB -s replace" echo -e "\t-i Import from Services or Profile (svservice,svprofile)" echo -e "\t-s sed Regex \'s/hi/hello/\'" exit 1 # Exit script after printing help } function reNameProfile { line=$( echo "$line" | xargs) id=` echo $line | awk -F ' ' '{print $1}' ` name=` echo $line | sed "s/${id}//g" ` name=$( echo "$name" | xargs) #name=` echo $name | awk -F ' ' '{print $LE}' ` newName=` echo $name | sed $sed ` echo -e "DEBUG:$name -> $newName ($id)" svcli value:set --id ${id} svobjects name "${newName}" ## Bitte entfernen, wenn ihr es getestet habt } function reServiceName { line=$( echo "$line" | xargs) id=` echo $line | awk -F ' ' '{print $1}' ` name=` echo $line | sed "s/${id}//g" ` name=$( echo "$name" | xargs) #name=` echo $name | awk -F ' ' '{print $LE}' ` newName=` echo $name | sed $sed ` echo -e "DEBUG:$name -> $newName ($id)" svcli value:set --id ${id} nagios serviceDescription "${newName}" ## Bitte entfernen, wenn ihr es getestet habt } function reNameHost { line=$( echo "$line" | xargs) id=` echo $line | awk -F ' ' '{print $1}' ` name=` echo $line | sed "s/${id}//g" ` name=$( echo "$name" | xargs) #name=` echo $name | awk -F ' ' '{print $LE}' ` newName=` echo $name | sed $sed ` echo -e "DEBUG:$name -> $newName ($id)" svcli value:set --id ${id} nagios hostName "${newName}" ## Bitte entfernen, wenn ihr es getestet habt } profilename=`svcli entity:list sv_service_profile | awk -F '"' '{print $1$2}' >/tmp/svprofile.txt` serviceName=`svcli entity:list sv_service | awk -F '"' '{print $1$2}' >/tmp/svservice.txt` serviceName=`svcli entity:list sv_host | awk -F '"' '{print $1$2}' >/tmp/svhost.txt` while getopts "i:s:" opt do case "$opt" in i ) inputtype= "$OPTARG" ;; s ) sed= $OPTARG ;; ? ) helpFunction ;; esac done if [ -z "$inputtype" ] || [ -z "sed" ] then helpFunction fi input= "/tmp/${inputtype}.txt" sed -i '1d' /tmp/${inputtype}.txt if [ $inputtype == "svprofile" ]; then while IFS= read -r line do reNameProfile done < "$input" fi if [ $inputtype == "svservice" ]; then while IFS= read -r line do reServiceName done < "$input" fi if [ $inputtype == "svhost" ]; then while IFS= read -r line do reNameHost done < "$input" fi exit 0 |