Adobe Acrobat Reader could not open 'dashboard.pdf'

Hi All,

I created a watcher with an email action to generate a dashboard pdf and send that out to an email address. In principal this works however the pdf cannot be opened with the error:

Adobe Acrobat Reader could not open 'dashboard.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

The watcher config I use is the following.

{
  "trigger": {
    "schedule": {
      "interval": "5m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "clog-*"
        ],
        "types": [
          "logs"
        ],
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "must": [
                {
                  "query_string": {
                    "query": "program:GW AND EnvID:p-xxxxn AND action:P6_ACCEPT_DEFAULT AND _exists_:hdr_subject AND cm_score: [0 TO 90]",
                    "analyze_wildcard": true
                  }
                },
                {
                  "range": {
                    "@timestamp": {
                      "gte": "now-5m",
                      "lte": "now"
                    }
                  }
                }
              ],
              "must_not": []
            }
          },
          "aggs": {
            "subjects": {
              "terms": {
                "field": "hdr_subject.keyword",
                "min_doc_count": 10,
                "size": 5,
                "order": {
                  "_count": "desc"
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "script": {
      "source": "if (ctx.payload.hits.total < 1) return false; for(int i=0; i < ctx.payload.aggregations.subjects.buckets.size(); i++) if (ctx.payload.aggregations.subjects.buckets[i].doc_count > 10) return true",
      "lang": "painless"
    }
  },
  "actions": {
    "standard_account": {
      "throttle_period_in_millis": 900000,
      "email": {
        "profile": "standard",
        "attachments": {
          "dashboard.pdf": {
            "http": {
              "request": {
                "scheme": "http",
                "host": "my.kibana.host",
                "port": 5601,
                "method": "post",
                "path": "/api/reporting/generate/dashboard/AV9R_W0QON_pt8a4d3oh&sync",
                "params": {},
                "headers": {
                  "kbn-xsrf": "reporting"
                },
                "auth": {
                  "basic": {
                    "username": "elastic"
                  }
                },
                "read_timeout_millis": 300000
              },
              "content_type": "application/pdf"
            }
          }
        },
        "priority": "high",
        "to": [
          "destination@example.com"
        ],
        "subject": "Possible spam run detected (TEST).",
        "body": {
          "text": "Possible spam run detected. Encountered {{ctx.payload.hits.total}} subjects in 5 minutes, see attached data"
        }
      }
    }
  }
}

If I generate the report from kibana it works fine.
Is there something else I need to set to generate a correct pdf?

what is the size of the produced PDF file?

can you share the output of the watch history or the execute watch api?

The size of the pdf is 158Kb. The output of the execution is this:

{
  "watch_id": "esrd",
  "state": "executed",
  "status": {
    "state": {
      "active": true,
      "timestamp": "2017-10-25T11:44:33.347Z"
    },
    "last_checked": "2017-10-25T12:43:36.790Z",
    "last_met_condition": "2017-10-25T12:43:36.790Z",
    "actions": {
      "standard_account": {
        "ack": {
          "timestamp": "2017-10-25T11:48:36.958Z",
          "state": "ackable"
        },
        "last_execution": {
          "timestamp": "2017-10-25T12:43:36.790Z",
          "successful": true
        },
        "last_successful_execution": {
          "timestamp": "2017-10-25T12:43:36.790Z",
          "successful": true
        },
        "last_throttle": {
          "timestamp": "2017-10-25T12:38:36.716Z",
          "reason": "throttling interval is set to [15 minutes] but time elapsed since last execution is [14 minutes, 59 seconds and 747 milliseconds]"
        }
      }
    }
  },
  "trigger_event": {
    "type": "schedule",
    "triggered_time": "2017-10-25T12:43:36.790Z",
    "schedule": {
      "scheduled_time": "2017-10-25T12:43:36.571Z"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "clog-*"
        ],
        "types": [
          "logs"
        ],
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "must": [
                {
                  "query_string": {
                    "query": "program:GW AND EnvID:p-xxxxxn AND action:P6_ACCEPT_DEFAULT AND _exists_:hdr_subject AND cm_score: [0 TO 90]",
                    "analyze_wildcard": true
                  }
                },
                {
                  "range": {
                    "@timestamp": {
                      "gte": "now-5m",
                      "lte": "now"
                    }
                  }
                }
              ],
              "must_not": []
            }
          },
          "aggs": {
            "subjects": {
              "terms": {
                "field": "hdr_subject.keyword",
                "min_doc_count": 10,
                "size": 5,
                "order": {
                  "_count": "desc"
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "script": {
      "source": "if (ctx.payload.hits.total < 1) return false; for(int i=0; i < ctx.payload.aggregations.subjects.buckets.size(); i++) if (ctx.payload.aggregations.subjects.buckets[i].doc_count > 10) return true",
      "lang": "painless"
    }
  },
  "metadata": {
    "name": "eSRD"
  },
  "result": {
    "execution_time": "2017-10-25T12:43:36.790Z",
    "execution_duration": 651,
    "input": {
      "type": "search",
      "status": "success",
      "payload": {
        "_shards": {
          "total": 6,
          "failed": 0,
          "successful": 6,
          "skipped": 0
        },
        "hits": {
          "hits": [],
          "total": 818,
          "max_score": 0
        },
        "took": 12,
        "timed_out": false,
        "aggregations": {
          "subjects": {
            "doc_count_error_upper_bound": 6,
            "sum_other_doc_count": 324,
            <snip>
          }
        }
      },
      "search": {
        "request": {
          "search_type": "query_then_fetch",
          "indices": [
            "clog-*"
          ],
          "types": [
            "logs"
          ],
          "body": {
            "size": 0,
            "query": {
              "bool": {
                "must": [
                  {
                    "query_string": {
                      "query": "program:GW AND EnvID:p-xxxxn AND action:P6_ACCEPT_DEFAULT AND _exists_:hdr_subject AND cm_score: [0 TO 90]",
                      "analyze_wildcard": true
                    }
                  },
                  {
                    "range": {
                      "@timestamp": {
                        "gte": "now-5m",
                        "lte": "now"
                      }
                    }
                  }
                ],
                "must_not": []
              }
            },
            "aggs": {
              "subjects": {
                "terms": {
                  "field": "hdr_subject.keyword",
                  "min_doc_count": 10,
                  "size": 5,
                  "order": {
                    "_count": "desc"
                  }
                }
              }
            }
          }
        }
      }
    },
    "condition": {
      "type": "script",
      "status": "success",
      "met": true
    },
    "actions": [
      {
        "id": "standard_account",
        "type": "email",
        "status": "success",
        "email": {
          "account": "standard_account",
          "message": {
            "id": "esrd_9b54d4e5-80b6-4403-ab51-8004433cc13b-2017-10-25T12:43:36.790Z",
            "from": "from@example.com",
            "priority": "high",
            "sent_date": "2017-10-25T12:43:36.907Z",
            "to": [
              "ouput@example.com"
            ],
            "subject": "Possible spam run detected (TEST).",
            "body": {
              "text": "Possible spam run detected. Encountered 818 subjects in 5 minutes, see attached data"
            }
          }
        }
      }
    ]
  },
  "messages": []
}

That looks ok, would it be possible to share that PDF? If you dont want to upload it, you can also email it to me directly, $firstname.$lastname@elastic.co (note the missing m at the end of the domain :slight_smile:

Thanks so much!

--Alex

I have send the email.

Thanks for looking.

What Elasticsearch version is this? I dont think you should use the HTTP input for your attachment but the dedicated reporting one

If you do, you can also get rid of the sync parameter.

I got this fixed after reading the docs a little better and resetup the action part.

Thanks for you pointer..

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.