-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfowatch.go
37 lines (32 loc) · 925 Bytes
/
infowatch.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 main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"time"
)
// Send Logs to InfoWatch
func sendLogsToInfoWatch(pid string, authorized string, user string, method string, resource string) (int, error) {
request_body, request_body_err := json.Marshal(map[string]string{
"authorized": authorized,
"user": user,
"method": method,
"resource": resource,
"time": time.Now().Format(time.RFC3339),
})
if request_body_err != nil {
return 1, request_body_err
}
url := os.Getenv("INFOWATCH_URL")
rev_proxy_username := os.Getenv("INFOWATCH_REV_PROXY_USERNAME")
rev_proxy_password := os.Getenv("INFOWATCH_REV_PROXY_PASSWORD")
req, _ := http.NewRequest("POST", fmt.Sprintf(url, pid), bytes.NewBuffer(request_body))
req.SetBasicAuth(rev_proxy_username, rev_proxy_password)
re, re_err := CLIENT.Do(req)
if re_err != nil {
return 1, re_err
}
return re.StatusCode, nil
}