-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathsplunk.go
38 lines (30 loc) · 1001 Bytes
/
splunk.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package splunk
import (
"fmt"
"net/url"
"encoding/json"
)
type SplunkConnection struct {
Username, Password, BaseURL string
sessionKey SessionKey
}
// SessionKey represents the JSON object returned from the Splunk authentication REST call
type SessionKey struct {
Value string `json:"sessionKey"`
}
// Login connects to the Splunk server and retrieves a session key
func (conn SplunkConnection) Login() (SessionKey, error){
data := make(url.Values)
data.Add("username", conn.Username)
data.Add("password", conn.Password)
data.Add("output_mode", "json")
response, err := conn.httpPost(fmt.Sprintf("%s/services/auth/login", conn.BaseURL), &data)
if err != nil {
return SessionKey{}, err
}
bytes := []byte(response)
var key SessionKey
unmarshall_error := json.Unmarshal(bytes, &key)
conn.sessionKey = key
return key, unmarshall_error
}