Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inbound from Prometheus issue #5

Open
Alexvianet opened this issue Oct 23, 2019 · 1 comment
Open

Inbound from Prometheus issue #5

Alexvianet opened this issue Oct 23, 2019 · 1 comment

Comments

@Alexvianet
Copy link

Alexvianet commented Oct 23, 2019

how to update Inbound integration script for Prometheus to make it work well with "group_by" alerts?

My body:

{
    "receiver": "xmatter-alert",
    "status": "firing",
    "alerts": [
        {
            "status": "firing",
            "labels": {
                "alertname": "ProbeSSLCertExpiryCritical",
                "env": "prod-gp2-om",
                "environment": "prometheus-master",
                "instance": "https://api.net/v2/info",
                "service": "probe",
                "severity": "critical"
            },
            "annotations": {
                "description": "The SSL certificate at endpoint `https://api.net/v2/info` will expire in 11d 20h 33m 53s",
                "summary": "Endpoint `https://api.net/v2/info` SSL certificate will expire in 11d 20h 33m 53s"
            },
            "startsAt": "2019-10-23T15:26:06.441177639Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "https://prometheus.net/graph?g0.expr=avg+by%28instance%2C+env%29+%28probe_ssl_earliest_cert_expiry%29+-+time%28%29+%3C+1.8144e%2B06&g0.tab=1",
            "fingerprint": "a5485df3cf855aef"
        },
        {
            "status": "firing",
            "labels": {
                "alertname": "ProbeSSLCertExpiryCritical",
                "env": "prod-gp2-om",
                "environment": "prometheus-master",
                "instance": "https://login.net/login",
                "service": "probe",
                "severity": "critical"
            },
            "annotations": {
                "description": "The SSL certificate at endpoint `https://login.net/login` will expire in 11d 20h 33m 53s",
                "summary": "Endpoint `https://login.net/login` SSL certificate will expire in 11d 20h 33m 53s"
            },
            "startsAt": "2019-10-23T15:26:06.441177639Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "https://prometheus.net/graph?g0.expr=avg+by%28instance%2C+env%29+%28probe_ssl_earliest_cert_expiry%29+-+time%28%29+%3C+1.8144e%2B06&g0.tab=1",
            "fingerprint": "a3a03dc78143ad60"
        },
        {
            "status": "firing",
            "labels": {
                "alertname": "ProbeSSLCertExpiryCritical",
                "env": "prod-gp2-om",
                "environment": "prometheus-master",
                "instance": "https://uaa.net/login",
                "service": "probe",
                "severity": "critical"
            },
            "annotations": {
                "description": "The SSL certificate at endpoint `https://uaa.net/login` will expire in 11d 20h 33m 53s",
                "summary": "Endpoint `https://uaa.net/login` SSL certificate will expire in 11d 20h 33m 53s"
            },
            "startsAt": "2019-10-23T15:26:06.441177639Z",
            "endsAt": "0001-01-01T00:00:00Z",
            "generatorURL": "https://prometheus.net/graph?g0.expr=avg+by%28instance%2C+env%29+%28probe_ssl_earliest_cert_expiry%29+-+time%28%29+%3C+1.8144e%2B06&g0.tab=1",
            "fingerprint": "c01b393165680508"
        }
    ],
    "groupLabels": {
        "alertname": "ProbeSSLCertExpiryCritical"
    },
    "commonLabels": {
        "alertname": "ProbeSSLCertExpiryCritical",
        "env": "prod-gp2-om",
        "environment": "prometheus-master",
        "service": "probe",
        "severity": "critical"
    },
    "commonAnnotations": {},
    "externalURL": "https://alertmanager.net",
    "version": "4",
    "groupKey": "{}/{severity=\"critical\"}:{alertname=\"ProbeSSLCertExpiryCritical\"}"
}

What i get in Inbox:
Screenshot from 2019-10-23 18-50-58

I want to get Annotations for all alerts like:
11111111111111111111

@xMTinkerer
Copy link
Contributor

I've often wondered about a good way to represent those. Would it ever be the case that array would be like REALLY REALLY REALLY huge? Say more than 30 items?

Anyway, thanks for including the payload. That made things much easier. I think we can do this with a couple fun uses of the javascript array map function. Getting the whitespace exactly like you have is not as fun with HTML, so hopefully this is ok? Otherwise we can look into tweaking the html to better visually break the sections up.

image

Change this line near the top:

properties.commonAnnotations_markup = buildMarkupFromJSON( data.commonAnnotations, true );

to this:

// Dig out the annotation objects
annotations = data.alerts.map( (alert) => { return alert.annotations } );

// Dig out the individual descriptions and summaries and store them separately
desc = annotations.map( (item) => { return item.description } );
summ = annotations.map( (item) => { return item.summary } );

// Put it all together with a nice label
properties.commonAnnotations_markup = 'Description:<br>' + desc.join( '<br>' ) + '<br>Summary:<br>' + summ.join( '<br>' );

// Ignore or remove this part.
//properties.commonAnnotations_markup = buildMarkupFromJSON( data.commonAnnotations, true );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants