尝试设置amazon ses for sensu
设置1 我有
handler-mailer.rb -j mailme_using_amazonses 在我的config.json
中
和func simpleDataRequest() {
//Get the url from url string
let url:URL = URL(string: "YOUR URL STRING")!
//Get the session instance
let session = URLSession.shared
//Create Mutable url request
var request = URLRequest(url: url as URL)
//Set the http method type
request.httpMethod = "POST"
//Set the cache policy
request.cachePolicy = URLRequest.CachePolicy.reloadIgnoringCacheData
//Post parameter
let paramString = "key=value"
//Set the post param as the request body
request.httpBody = paramString.data(using: String.Encoding.utf8)
let task = session.dataTask(with: request as URLRequest) {
(data, response, error) in
guard let _:Data = data as Data?, let _:URLResponse = response , error == nil else {
//Oops! Error occured.
print("error")
return
}
//Get the raw response string
let dataString = String(data: data!, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
//Print the response
print(dataString!)
}
//resume the task
task.resume()
}
位于我的handler-mailer.rb
文件夹
当我在命令行上运行时,我收到错误
/etc/sensu/plugins
我的mailme_using_amazonses有以下
ruby /etc/sensu/plugins/handler-mailer.rb -j mailme_using_amazonses
/var/lib/gems/1.9.1/gems/mixlib-cli-1.7.0/lib/mixlib/cli.rb:230:in `parse_options': invalid option: -j (OptionParser::InvalidOption)
from /var/lib/gems/1.9.1/gems/sensu-plugin-1.4.3/lib/sensu-handler.rb:18:in `initialize'
from /var/lib/gems/1.9.1/gems/sensu-plugin-1.4.3/lib/sensu-handler.rb:78:in `new'
from /var/lib/gems/1.9.1/gems/sensu-plugin-1.4.3/lib/sensu-handler.rb:78:in `block in <class:Handler>'
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- erubis (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /etc/sensu/plugins/handler-mailer.rb:20:in `<main>'
设置2
在{
"handlers": {
"mailer-ses": {
"mail_from": "from@example.com",
"mail_to": "to@example.com",
"use_ami_role": true,
"secret_key": "MyKey",
"access_key": "MyAccess",
"region": "us-west-2"
}
}
}
我有以下
config.json
当我重新启动{
.. other config ..
"handlers": {
"handler-ses": { **HERE I ALSO TRIED "ses"**
"mail_from": "from@example.com",
"mail_to": "to@example.com",
"use_ami_role": true,
"access_key": "accesskey",
"secret_key": "secretekey",
"region": "us-west-2",
"subscriptions": {
"subscription_name": {
"mail_to": "teamemail@example.com"
}
}
}
}
}
时,我收到以下错误
sensu-server
我在这里缺少什么?
答案 0 :(得分:1)
我解决了这个问题。我读了handler-ses.rb
文件。这里注意到配置应该在ses.json
。我将config.json
json中的设置2 ses配置复制到ses.json
并将其放在/etc/sensu/handers
文件夹下。错误消失了。我还没收到电子邮件。
在我发送ses
电子邮件后,我会更新此答案。