j6s / mailcow-exporter

MIT License
58 stars 12 forks source link

error 500 #1

Closed badsmoke closed 4 years ago

badsmoke commented 4 years ago

hello i get this error, i have the newest mailcow version installed

empty json array '[]'

020/09/05 18:41:41 https://mail.domain.tld/api/v1/get/mailq/all
2020/09/05 18:41:41 &errors.errorString{s:"Error while updating metrics of provider.Mailq: \"Could not parse JSON: \\\"json: cannot unmarshal object into Go value of type []provider.queueResponseItem\\\"\""}
j6s commented 4 years ago

That's interesting. Can you try issuing a manual API request in order to verify, that the returned data is in fact JSON?

Something like this should do:

$ curl 'https://mail.domain.tld/api/v1/get/mailq/all' -H 'X-Api-Key: YOUR-API-KEY-HERE'

Things to look for in the response body

  {
    "queue_name": "deferred",
    "queue_id": "0E348C0104",
    "arrival_time": 1599158539,
    "message_size": 22076,
    "sender": "foo@mail.domain.tld",
    "recipients": [
      "..."
    ]
  }
j6s commented 4 years ago

Looking at possible error sources, I have discovered, that currently authentication errors are not handled correctly: They return the following JSON

{
  "type": "error",
  "msg": "authentication failed"
}

which in fact would lead to a JSON marshalling error similar to the one you posted. It would also happen on the Mailq provider since that's the first one that sends a request to the API.

Not sure if this is the same problem or not though. Please report back with your findings.

j6s commented 4 years ago

I also just pushed a commit to main (should be in docker hub soon) which makes errors more verbose in order to help track issues with API requests down. If you could try again with that commit I would very much appreciate it.

badsmoke commented 4 years ago

the result from the curl command is a empty json struct

{}

the log output with the newes exporter version

2020/09/06 09:01:21 https://mail.domain.tld/api/v1/get/mailq/all
2020/09/06 09:01:21 &errors.errorString{s:"Error while updating metrics of provider.Mailq:\nCould not parse JSON response from endpoint `api/v1/get/mailq/all`: \njson: cannot unmarshal object into Go value of type []provider.queueResponseItem \n\nResponse body received: \n{}"}
j6s commented 4 years ago

That's very interesting. Between first implementing mailcow-exporter and now my instance was unblocked by another server and I can confirm, that the endpoint will return an array, if there are queued items but and empty JSON object if there is nothing in the queue now. This is a bug in the mailcow API, but I will see how I can also handle it in the exporter.

Thanks for the help debugging.

j6s commented 4 years ago

[01db707] Should resolve this issue by ignoring API response errors. This is not ideal, but until fixed on the mailcow side it should do the job.

badsmoke commented 4 years ago

I have to thank you for the quick feedback

I have built a rspamd_exporter for mailcows rspamd, so I am very interested in this exporter :-)

with the latest version, some data arrives now but not all, but hopefully this will change when mailcow reacts to your issue

edit: ah on my second mail server all data arrives, so I really don't seem to have any quarantine data on my test server

j6s commented 4 years ago

Interesting - also: As part of https://github.com/mailcow/mailcow-dockerized/issues/1695 a new /api/v1/get/logs/rspamd-stats has been implemented. I haven't looked at it yet, but it could be promising

badsmoke commented 4 years ago

very cool thanks for the hint, I did not even notice