j6s / mailcow-exporter

MIT License
58 stars 12 forks source link

mailbox provider not successful #3

Closed badsmoke closed 3 years ago

badsmoke commented 3 years ago

hello, i made an update of the cow yesterday, unfortunately the mailbox metrics don't work anymore.

# HELP mailcow_exporter_success 
# TYPE mailcow_exporter_success gauge
mailcow_exporter_success{host="mail.example.com",provider="provider.Container"} 1
mailcow_exporter_success{host="mail.example.com",provider="provider.Mailbox"} 0
mailcow_exporter_success{host="mail.example.com",provider="provider.Mailq"} 1
mailcow_exporter_success{host="mail.example.com",provider="provider.Quarantine"} 1
mailcow_exporter_success{host="mail.example.com",provider="provider.Rspamd"} 1

log output

2021/07/14 05:54:19 https://mail.example.com/api/v1/get/quarantine/all
2021/07/14 05:54:19 https://mail.example.com/api/v1/get/status/containers
2021/07/14 05:54:19 https://mail.example.com/api/v1/get/logs/rspamd-stats
2021/07/14 05:54:34 https://mail.example.com/api/v1/get/mailq/all
2021/07/14 05:54:34 https://mail.example.com/api/v1/get/mailbox/all
2021/07/14 05:54:34 Error while updating metrics of provider.Mailbox:
Could not parse JSON response from endpoint `api/v1/get/mailbox/all`: 
json: cannot unmarshal number into Go struct field mailboxItem.last_imap_login of type string 
[
    {
        "username": "test.test@example.com",
        "active": 1,
        "active_int": 1,
        "domain": "example.com",
        "relayhost": null,
        "name": "Test test",
        "local_part": "test.test",
        "quota": 10485760000,
        "messages": 986,
        "attributes": {
            "force_pw_update": "0",
            "tls_enforce_in": "0",
            "tls_enforce_out": "0",
            "sogo_access": "1",
            "mailbox_format": "maildir:",
            "quarantine_notification": "never",
            "imap_access": "1",
            "pop3_access": "1",
            "smtp_access": "1",
            "xmpp_access": "1",
            "xmpp_admin": "0",
            "quarantine_category": "reject",
            "passwd_update": "0",
            "relayhost": "0"
        },
        "quota_used": 334172031,
        "percent_in_use": 3,
        "percent_class": "success",
        "last_imap_login": 0,
        "last_smtp_login": 0,
        "last_pop3_login": 0,
        "max_new_quota": 51220840448,
        "spam_aliases": 0,
        "pushover_active": 0,
        "rl": false,
        "rl_scope": "domain",
        "is_relayed": 0
    },

i think you can fix it by simply change string to int ? in the file mailcow-exporter/provider/mailbox.go

type mailboxItem struct {
    Username      string `json:"username"`
    LastImapLogin string `json:"last_imap_login"`
    Quota         int    `json:"quota"`
    QuotaUsed     int    `json:"quota_used"`
    Messages      int    `json:"messages"`
}

I don't know anything about go, but I have commented out last login for the time being, so it works.

j6s commented 3 years ago

Thanks for reporting this. I haven't updated my instance in a couple of weeks, so I guess the API must have changed. Ideally I would like to keep it backwards compatible, so older and newer instances are supported.

I'll upgrade my instance later today and add a test for both cases.

j6s commented 3 years ago

I have updated my instance and can now confirm, that the field now contains an integer. Currently working on a fix that supports both, strings and integers

j6s commented 3 years ago

Version 1.3.1 solves the issue: https://github.com/j6s/mailcow-exporter/releases/tag/1.3.1

The docker image for the release should be built soon, too

badsmoke commented 3 years ago

perfect thanks for the always quick help