sjj
sjj

Reputation: 23

'File too long' error while using POST alertrule via jenkins pipeline

I am using the format based of https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#provisioned-alert-rule and https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/#route-post-alert-rule.

My first pipeline worked so I tried expanding on it, not sure why it gives a File too long error.

Pipeline1 (working):

pipeline {
    agent any

    environment {
        GRAFANA_TOKEN = credentials('grafana-service-account') // Grafana API token stored securely
        GRAFANA_URL = "https://sjgrafana.duckdns.org"
    }

    stages {
        stage('Post Alert Rule to Grafana') {
            steps {
                script {
                    sh """
                        curl -v -k -X POST "${GRAFANA_URL}/api/v1/provisioning/alert-rules" \\
                            -H "Content-Type: application/json" \\
                            -H "Authorization: Bearer ${GRAFANA_TOKEN}" \\
                            -d '{
                                "title": "Instance Down Alert",
                                "condition": "A",
                                "data": [
                                    {
                                        "datasourceUid": "bea23y3z4smbkd",
                                        "model": {
                                            "refId": "A",
                                            "expr": "up{instance=\\"172.20.20.3:9117\\"} != 0",
                                            "intervalMs": 1000,
                                            "maxDataPoints": 43200,
                                            "type": "query"
                                        },
                                        "queryType": "",
                                        "refId": "A",
                                        "relativeTimeRange": {
                                            "from": 600,
                                            "to": 0
                                        }
                                    }
                                ],
                                "execErrState": "Error",
                                "noDataState": "NoData",
                                "for": "1m",
                                "folderUID": "cea24bsrl5m2of",
                                "ruleGroup": "VNC_Client_Group",
                                "annotations":{},
                                "labels": {},
                                "orgID": 1
                            }'
                    """
                }
            }
        }
    }
}

Pipeline2 (not working):

#working

pipeline {
    agent any

    environment {
        GRAFANA_TOKEN = credentials('grafana-service-account') // Grafana API token stored securely
        GRAFANA_URL = "https://sjgrafana.duckdns.org"
    }

    stages {
        stage('Post Alert Rule to Grafana') {
            steps {
                script {
                    sh """
                        curl -v -k -X POST "${GRAFANA_URL}/api/v1/provisioning/alert-rules" \\
                            -H "Content-Type: application/json" \\
                            -H "Authorization: Bearer ${GRAFANA_TOKEN}" \\
                            -d '{
                                "title": "Instance Down Alert",
                                "condition": "A",
                                "data": [
                                    {
                                        "datasourceUid": "bea23y3z4smbkd",
                                        "model": {
                                            "refId": "A",
                                            "expr": "up{instance=\\"172.20.20.3:9117\\"} != 0",
                                            "intervalMs": 1000,
                                            "maxDataPoints": 43200,
                                            "type": "query"
                                        },
                                        "queryType": "",
                                        "refId": "A",
                                        "relativeTimeRange": {
                                            "from": 600,
                                            "to": 0
                                        }
                                    }
                                ],
                                "execErrState": "Error",
                                "noDataState": "NoData",
                                "for": "1m",
                                "folderUID": "cea24bsrl5m2of",
                                "ruleGroup": "VNC_Client_Group",
                                "annotations":{},
                                "labels": {},
                                "orgID": 1
                            }'
                    """
                }
            }
        }
    }
}

Upvotes: 0

Views: 50

Answers (0)

Related Questions