SOS alert on ntg fail auth
parent
a38a627f5a
commit
a6d5ae606a
|
|
@ -121,9 +121,6 @@ func (ntg NTGVision) searchJob(id int64) (io.ReadCloser, error) {
|
|||
defer resp.Body.Close()
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
logtr.Debugf("fetch ntg job info %+v: %d: %s", request, resp.StatusCode, b)
|
||||
if resp.StatusCode > 400 && resp.StatusCode < 500 && resp.StatusCode != 404 && resp.StatusCode != 410 {
|
||||
return nil, ErrNoAuth
|
||||
}
|
||||
return io.NopCloser(bytes.NewReader(b)), nil
|
||||
}
|
||||
|
||||
|
|
@ -173,15 +170,10 @@ func (ntg NTGVision) WithMock() NTGVision {
|
|||
|
||||
func (ntg NTGVision) SearchJob(id int64) (ntgVisionJobInfo, error) {
|
||||
rc, err := ntg.searcher.searchJob(id)
|
||||
if err == ErrNoAuth {
|
||||
if err := ntg.refreshAuth(); err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
rc, err = ntg.searcher.searchJob(id)
|
||||
}
|
||||
if err != nil {
|
||||
return ntgVisionJobInfo{}, err
|
||||
}
|
||||
defer rc.Close()
|
||||
var result ntgVisionJobInfo
|
||||
err = json.NewDecoder(rc).Decode(&result)
|
||||
return result, err
|
||||
|
|
@ -243,6 +235,14 @@ func (ntg NTGVision) search(states []config.State) (io.ReadCloser, error) {
|
|||
}
|
||||
|
||||
func (ntg NTGVision) refreshAuth() error {
|
||||
err := ntg.refreshAuth()
|
||||
if err != nil {
|
||||
logtr.SOSf("failed to refresh ntg auth: %v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (ntg NTGVision) _refreshAuth() error {
|
||||
logtr.Infof("refreshing ntg auth...")
|
||||
b, _ := json.Marshal(map[string]string{
|
||||
"username": config.Get().Brokers.NTG.Username,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"Log": {
|
||||
"Path": "/tmp/truckstop.log",
|
||||
"Level": "deb",
|
||||
"Level": "error",
|
||||
"SOSMatrix": {
|
||||
"ReceiveEnabled": true,
|
||||
"Mock": true,
|
||||
"Mock": false,
|
||||
"Homeserver": "https://m.bltrucks.top",
|
||||
"Username": "@bot.m.bltrucks.top",
|
||||
"Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS",
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
"Message": {
|
||||
"Matrix": {
|
||||
"ReceiveEnabled": true,
|
||||
"Mock": true,
|
||||
"Mock": false,
|
||||
"Homeserver": "https://m.bltrucks.top",
|
||||
"Username": "@bot.m.bltrucks.top",
|
||||
"Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS",
|
||||
|
|
@ -69,7 +69,7 @@
|
|||
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
|
||||
}
|
||||
},
|
||||
"Once": true,
|
||||
"Once": false,
|
||||
"Brokers": {
|
||||
"NTG": {
|
||||
"JobInfo": true,
|
||||
|
|
|
|||
Loading…
Reference in New Issue