@@ -27,6 +27,7 @@ import (
2727 "time"
2828
2929 splcommon "github.com/splunk/splunk-operator/pkg/splunk/common"
30+ logf "sigs.k8s.io/controller-runtime/pkg/log"
3031)
3132
3233// SplunkHTTPClient defines the interface used by SplunkClient.
@@ -946,31 +947,44 @@ func (c *SplunkClient) RestartSplunk() error {
946947// Updates conf files and their properties
947948// See https://help.splunk.com/en/splunk-enterprise/leverage-rest-apis/rest-api-reference/10.0/configuration-endpoints/configuration-endpoint-descriptions
948949func (c * SplunkClient ) UpdateConfFile (fileName , property , key , value string ) error {
950+ logger := logf .Log .WithName ("UpdateConfFile" )
951+ logger .V (1 ).Info ("Creating/ensuring object in conf file" , "fileName" , fileName , "property" , property )
952+
949953 // Creates an object in a conf file if it doesn't exist
950954 endpoint := fmt .Sprintf ("%s/servicesNS/nobody/system/configs/conf-%s" , c .ManagementURI , fileName )
951955 body := fmt .Sprintf ("name=%s" , property )
952956
957+ logger .V (2 ).Info ("POST request to create conf object" , "endpoint" , endpoint , "body" , body )
953958 request , err := http .NewRequest ("POST" , endpoint , strings .NewReader (body ))
954959 if err != nil {
960+ logger .Error (err , "Failed to create HTTP request for conf object creation" , "endpoint" , endpoint )
955961 return err
956962 }
957963
958964 expectedStatus := []int {200 , 201 , 409 }
959965 err = c .Do (request , expectedStatus , nil )
960966 if err != nil {
967+ logger .Error (err , "Failed to create/ensure conf object" , "endpoint" , endpoint , "property" , property )
961968 return err
962969 }
963970
964971 // Updates a property of an object in a conf file
965972 endpoint = fmt .Sprintf ("%s/servicesNS/nobody/system/configs/conf-%s/%s" , c .ManagementURI , fileName , property )
966973 body = fmt .Sprintf ("%s=%s" , key , value )
967974
975+ logger .V (2 ).Info ("POST request to update conf property" , "endpoint" , endpoint , "body" , body , "key" , key , "value" , value )
968976 request , err = http .NewRequest ("POST" , endpoint , strings .NewReader (body ))
969977 if err != nil {
978+ logger .Error (err , "Failed to create HTTP request for conf property update" , "endpoint" , endpoint )
970979 return err
971980 }
972981
973982 expectedStatus = []int {200 , 201 }
974983 err = c .Do (request , expectedStatus , nil )
984+ if err != nil {
985+ logger .Error (err , "Failed to update conf property" , "endpoint" , endpoint , "key" , key , "value" , value )
986+ } else {
987+ logger .V (1 ).Info ("Successfully updated conf property" , "fileName" , fileName , "property" , property , "key" , key , "value" , value )
988+ }
975989 return err
976990}
0 commit comments