X-pack watch: error while sending mail with PDF attachment

I have configured the watch for an index and saved successfully .
Below is the code snippet for actions{...} section only.

  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "attachments": {
          "dashboard.pdf": {
            "http": {
              "request": {
                "scheme": "http",
                "host": "localhost",
                "port": 5601,
                "method": "get",
                "path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",
                "params": {},
                "headers": {}
              },
              "content_type": "application/pdf"
            }
          }
        },
        "priority": "high",
        "to": [
          "kiran.ku.ila@act.com"
        ],
        "subject": "Watcher Report on closed tickets",
        "body": {
          "text": " Watcher \"{{ctx.watch_id}}\" Encountered {{ctx.payload.hits.total}} log entries, see attached data"
        }
      }
    }
  }

when the trigger is executed on a specified time interval, this actions block is executed and trying to send a mail attaching the PDF, but it is failing with the below mentioned error:

 "reason": "Watch[_inlined_] attachment[dashboard.pdf] HTTP error status host[localhost], port[5601], method[GET], path[/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu], status[401]"

I tried modifying the code for authenticating and to attach the PDF in the mail to send.
As shown below which is in bold lettering :

"actions": {
"send_email": {
"email": {
"profile": "standard",
"attachments": {
"dashboard.pdf": {
"http": {
"request": {
"scheme": "http",
"host": "localhost",
"port": 5601,
"method": "get",
"path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",
"params": {},
"headers": {}
},
"content_type": "application/pdf",
"auth": {
"basic":{
"username":"elastic",
"password":"*"
}
}
}
}
},
"priority": "high",
"to": [
"kiran.ku.ila@act.com"
],
"subject": "Watcher Report on closed tickets",
"body": {
"text": " Watcher "{{ctx.watch_id}}" Encountered {{ctx.payload.hits.total}} log entries, see attached data"
}
}
}

but i have ended up with an error :
Watcher: [parse_exception] Unknown field name [auth] in http request attachment configuration

Could you please help me out where should i place the authentication tag ("auth" tag) so that i can successfully run and send the mail with attachment.

I have resolved this issue, by modifying the script as shown below:
where i have added the "auth" code just below "headers".

"request": {
                "scheme": "http",
                "host": "localhost",
                "port": 5601,
                "method": "get",
                "path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",
                "params": {},
                "headers": {},
                "auth": {
                  "basic": {
                    "username": "elastic"
					"password": "****"
                  }
                }
              },
1 Like

Hey,

glad you sorted it out! Should we improve our documentation somewhere, so people dont fall into this trap or did you maybe even found some wrong documentation that requires fixing?

In addition, you dont need to specify empty params and headers. Also you can just specify a single url field like this, instead of scheme, host, port, path and method:

"url" : "http://localhost:5601/api/report..."

--Alex

HI Alex,

As you said i have tried the above with single url option (which was documented in www.elastic.co), it was giving an error so tired with host, port, path and method options.. it worked for me.. not sure exactly.. but i suspect there was an issue with the json structure or expecting any additional field which was missing when we use **url** option.
some times i used to get 405 or 404 with exceptions :
watch[jira] reporting[error_report.pdf] Error response when trying to trigger reporting generation host[localhost], port[5601] method[POST], path[/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu], status[404]"

when i tried with replacing the url code with host, port ,path and method it was able to get the report successfully.

probably you can try it once from your end..
Thank you.

Hey,

if you can share the snippet of your reporting section, that would be great!

--Alex

Hi Alex,

The below is the code snippet..:
The below path : is the downloaded URL path for pdf

  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "attachments": {
          "dashboard.pdf": {
            "http": {
              "request": {
                "scheme": "http",
                "host": "localhost",
                "port": 5601,
                "method": "get",
                "path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",
                "params": {},
                "headers": {},
                "auth": {
                  "basic": {
                    "username": "elastic",
					"password": "****"
                  }
                }
              },
              "content_type": "application/pdf"
            }
          }
        },
        "priority": "high",
        "to": [
          "kiran.i@acc.com"
        ],
        "subject": "Watcher Report on closed tickets",
        "body": {
          "text": " Watcher \"{{ctx.watch_id}}\" Encountered {{ctx.payload.hits.total}} log entries, see attached data"
        }
      }
    }
  }

also the snippet where it does not work would be useful for comparison. I'm of course more interested in the case, that does not work.

And the output of the execute watch api or a watch history record in the bad case would be nice as well (note, you might want to redact things out there, like IP addresses).

--Alex

The below code ..which is not working and throwing an exception when running:

  "actions": {
    "my-logging-action": {
      "logging": {
        "level": "info",
        "text": "There are {{ctx.payload.hits.total}} documents in your index. Threshold is 3."
      }
    },
    "send_email": {
      "email": {
        "profile": "standard",
        "priority": "high",
        "to": [
          "kiran.i@acc.com"
        ],
        "subject": "Encountered {{ctx.payload.hits.total}} errors",
        "body": {
          "text": "Too many error in the system, see attached data"
        },
		"attachments" : {
			"dashboard.pdf" : {
				"reporting" : {
					"url": "http://localhost:5601/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu"
				}
			}
		}
      }
    }
  }

Hi kIran,

In this case,let say am scheduling every month automatically,can we use the same path or each every time we should change the path and replace the existing path

("path": "/api/reporting/jobs/download/j49gc5ey090cdda7d96hz8fu",)

Thanks,
Raj

In this case we are mailing the PDF which was downloaded earlier,so need to change the path for the latest file which is downloaded

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