Failed to send event to MongoDb - mongodb

I am using logstash to collect data from android device using http-poller as input plugin. I want to store the collected data in a NoSQL(mongodb) using mongodb as output plugin. I have successfully set up the configuration file but when I run my set-up, I get the following error:
Failed to send event to MongoDB {:event=>#, #cancelled=false, #data={"error"=>501, "#version"=>"1", "#timestamp"=>"2016-10-03T18:02:11.337Z", "http_poller_metadata"=>{"name"=>"some_other_service", "host"=>"s18660276.domainepardefaut.fr", "request"=>{"method"=>"post", "url"=>"http://127.0.0.1/web/app.php/api/addsmartlog"}, "runtime_seconds"=>0.526, "code"=>200, "response_headers"=>{"date"=>"Mon, 03 Oct 2016 18:02:11 GMT", "server"=>"Apache/2.2.22 (Debian)", "x-powered-by"=>"PHP/5.5.30-1~dotdeb+7.1", "cache-control"=>"no-cache", "content-length"=>"13", "keep-alive"=>"timeout=5, max=100", "connection"=>"Keep-Alive", "content-type"=>"application/json"}, "response_message"=>"OK", "times_retried"=>0}}, #metadata={}, #accessors=#501, "#version"=>"1", "#timestamp"=>"2016-10-03T18:02:11.337Z", "http_poller_metadata"=>{"name"=>"some_other_service", "host"=>"s18660276.domainepardefaut.fr", "request"=>{"method"=>"post", "url"=>"http://127.0.0.1/web/app.php/api/addsmartlog"}, "runtime_seconds"=>0.526, "code"=>200, "response_headers"=>{"date"=>"Mon, 03 Oct 2016 18:02:11 GMT", "server"=>"Apache/2.2.22 (Debian)", "x-powered-by"=>"PHP/5.5.30-1~dotdeb+7.1", "cache-control"=>"no-cache", "content-length"=>"13", "keep-alive"=>"timeout=5, max=100", "connection"=>"Keep-Alive", "content-type"=>"application/json"}, "response_message"=>"OK", "times_retried"=>0}}, #lut={"http_poller_metadata"=>[{"error"=>501, "#version"=>"1", "#timestamp"=>"2016-10-03T18:02:11.337Z", "http_poller_metadata"=>{"name"=>"some_other_service", "host"=>"s18660276.domainepardefaut.fr", "request"=>{"method"=>"post", "#timestamp"=>"2016-10-03T18:02:11.337Z", "http_poller_metadata"=>{"name"=>"some_other_service", "host"=>"s18660276.domainepardefaut.fr", "request"=> "runtime_seconds"=>0.526, "code"=>200, "response_headers"=>{"date"=>"Mon, 03 Oct 2016 18:02:11 GMT", "server"=>"Apache/2.2.22 (Debian)", "x-powered-by"=>"PHP/5.5.30-1~dotdeb+7.1", "cache-control"=>"no-cache", "content-length"=>"13", "keep-alive"=>"timeout=5, max=100", "connection"=>"Keep-Alive", "content-type"=>"application/json"}, "response_message"=>"OK", "times_retried"=>0}}, "#timestamp"]}>>, :exception=>#"admin"}, #server_selection_timeout=30>>, :backtrace=>["/opt/logstash/vendor/bundle/jruby/1.9/gems/mongo-2.0.6/lib/mongo/server_selector/selectable.rb:99:in select_server'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/mongo-2.0.6/lib/mongo/cluster.rb:122:innext_primary'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/mongo-2.0.6/lib/mongo/collection.rb:190:in insert_many'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/mongo-2.0.6/lib/mongo/collection.rb:175:ininsert_one'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-mongodb-2.0.5/lib/logstash/outputs/mongodb.rb:56:in receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/outputs/base.rb:109:inmulti_receive'", "org/jruby/RubyArray.java:1613:in each'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/outputs/base.rb:109:inmulti_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/output_delegator.rb:130:in worker_multi_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/output_delegator.rb:114:inmulti_receive'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:301:in output_batch'", "org/jruby/RubyHash.java:1342:ineach'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:301:in output_batch'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:232:inworker_loop'", "/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.4.0-java/lib/logstash/pipeline.rb:201:in `start_workers'"], :level=>:warn}
^CSIGINT received. Shutting down the agent. {:level=>:warn}
Can anyone help out?

Related

unable to upload an image file to slack through hubot

I am trying to get an image of a web page using pageres package, And post the image to slack using hubot. I am able to get the image, but for some reason i am not able to post it to slack using slack upload api. Here is my code, can you tell me what could be wrong? (not a coffee lint issue)
fs = require("fs")
Pageres = require('pageres')
util = require("util")
request = require("request")
module.exports = (robot) ->
robot.respond /screenshot page (\S*)?( at )?(\S*)?/i, (msg) ->
pageres = new Pageres({delay: 30})
domain = msg.match[1].replace("http://", "")
if msg.match[3] == undefined
size = '960x1024'
else
size = msg.match[3]
dest = './screenshots'
msg.send "Acquiring screenshot of #{domain}"
pageres.src(domain, [size]).dest(dest)
pageres.run (err) ->
if err
robot.logger.error err
msg.send "Um..., you better check the log"
else
opts = {
method: 'POST',
uri: 'https://slack.com/api/files.upload',
formData: {
channels: process.env.HUBOT_SCREENSHOT_SLACK_CHANNEL,
initial_comment: "Screenshot of #{domain}",
token: process.env.HUBOT_SLACK_TOKEN,
file: fs.createReadStream("#{dest}/#{domain}.png")
}
}
request.post opts, (error, response, body) ->
if error
robot.logger.error error
else
robot.logger.debug 'screenshot posted to slack'
return
The bot is connected to slack, and receiving messages from slack, parsing them fine and getting the image back to the local destination, but not able to post it to slack, There are no errors as well in the log.
[Wed Apr 11 2018 16:16:47 GMT+0000 (UTC)] DEBUG Received message: '#hubot screenshot page http://www.google.com' in channel: ****, from: ******
[Wed Apr 11 2018 16:16:47 GMT+0000 (UTC)] DEBUG Message '#hubot screenshot page http://www.google.com' matched regex //^\s*[#]?hubot[:,]?\s*(?:screenshot page (\S*)?( at )?(\S*)?)/i/; listener.options = { id: null }
[Wed Apr 11 2018 16:16:47 GMT+0000 (UTC)] DEBUG Executing listener callback for Message '#hubot screenshot page http://www.google.com'
[Wed Apr 11 2018 16:16:47 GMT+0000 (UTC)] DEBUG Sending to *****: Acquiring screenshot of www.google.com
You can use curl command which can be called using child_process to upload a file in the channel.
curl -F file=#dramacat.gif -F channels=C024BE91L,#general -F token=xxxx-xxxxxxxxx-xxxx https://slack.com/api/files.upload
It seems the formData property in your opts variable should be slightly different like this:
formData: {
token: process.env.HUBOT_SLACK_TOKEN,
title: "Screenshot of #{domain}",
filename: "image.png",
filetype: "auto",
channels: channel_id,
file: fs.createReadStream("path_to_your_image"),
}
The channel_id is your slack channel id which you can see in the browser address bar when you access the channel.

Sorting a Meteor Cursor

I am using Ionic 2 with Meteor/Mongo.
I am trying to sort a Cursor, but find it just keeps the original order which the items were inserted.
model
interface Chat {
_id?: string;
memberIds?: string[];
title?: string;
subTitle?: string;
picture?: string;
lastMessage?: Message;
lastMessageCreatedAt?: Date;
receiverComp?: Tracker.Computation;
lastMessageComp?: Tracker.Computation;
}
ts
private sortLocalChats(): void {
this.localChatCursor = this.localChatCollection.find({}, { sort: { lastMessageCreatedAt: -1 } });
this.localChatCursor.forEach((chat: Chat) => {
console.log(chat.title+' '+chat.lastMessageCreatedAt);
});
console.log('==> loaded sorted local chats: ' + this.localChatCollection.find().count());
output
Ashton Marais Thu Oct 06 2016 16:50:36 GMT+0800 (CST)
Ashton Marais Wed Oct 12 2016 21:20:18 GMT+0800 (CST)
ghjghj ghjghg Wed Oct 05 2016 23:37:49 GMT+0800 (CST)
Brett Simpson Thu Oct 06 2016 23:52:05 GMT+0800 (CST)
==> loaded sorted local chats: 4
I would have expected this to be sorted by lastMessageCreatedAt.
Any help appreciated.
To get sorted results you probably need to call fetch() first. So in the above example this works:
this.localChatCursor.fetch().forEach(...);

Retrieve AEM Page Properties via Search/QueryBuilder API

Is there a way to retrieve data stored as page metadata (Page Properties) stored in a separate JCR node via the QueryBuilder API?
Example:
The search results should include the data under ~/article-1/jcr:content/thumbnail. However, the only results I am getting are data under the ~article-1/jcr:content/content (a parsys included on the template).
An example query:
http://localhost:4502/bin/querybuilder.json?p.hits=full&path=/content/path/to/articles
Results in (snippet):
{
"jcr:path":"/content/path/to/articles/article-1",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:primaryType":"cq:Page"
},
{
"jcr:path":"/content/path/to/articles/article-1/jcr:content",
"sling:resourceType":"myapp/components/global/page/productdetail",
"jcr:lockIsDeep":true,
"jcr:uuid":"4ddebe08-82e1-44e9-9197-4241dca65bdf",
"jcr:title":"Article 1",
"jcr:mixinTypes":[
"mix:lockable",
"mix:versionable"
],
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:baseVersion":"24cabbda-1e56-4d37-bfba-d0d52aba1c00",
"cq:lastReplicationAction":"Activate",
"jcr:isCheckedOut":true,
"cq:template":"/apps/myapp/templates/global/productdetail",
"cq:lastModifiedBy":"admin",
"jcr:primaryType":"cq:PageContent",
"jcr:predecessors":[
"24cabbda-1e56-4d37-bfba-d0d52aba1c00"
],
"cq:tags":[
"mysite:mytag"
],
"jcr:createdBy":"admin",
"jcr:versionHistory":"9dcd41d4-2e10-4d52-b0c0-1ea20e102e68",
"cq:lastReplicatedBy":"admin",
"cq:lastModified":"Mon Dec 09 2013 17:57:59 GMT-0500",
"cq:lastReplicated":"Mon Dec 16 2013 11:42:54 GMT-0500",
"jcr:lockOwner":"admin"
}
Search configuration is the out-of-the-box default.
EDIT: Data is returning in JSON, however, is not accessable in the API:
Result:
{
"success":true,
"results":2,
"total":2,
"offset":0,
"hits":[
{
"jcr:path":"/content/path/to/articles/article-a",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:27:01 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"jcr:lastModified":"Wed Dec 04 2013 12:10:47 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
},
{
"jcr:path":"/content/path/to/articles/article-1",
"jcr:createdBy":"admin",
"jcr:created":"Tue Dec 03 2013 16:26:51 GMT-0500",
"jcr:primaryType":"cq:Page",
"jcr:content":{
"sling:resourceType":"path/to/components/global/page/productdetail",
"_comment":"// ***SNIP*** //",
"thumbnail":{
"jcr:lastModifiedBy":"admin",
"imageRotate":"0",
"fileReference":"/content/dam/path/to/IBMDemo/apparel/women/wsh005_shoes/WSH005_0533_is_main.jpg",
"jcr:lastModified":"Mon Dec 09 2013 17:57:58 GMT-0500",
"jcr:primaryType":"nt:unstructured"
}
}
}
]
}
Implementation code:
searchCriteria.put("path", path);
searchCriteria.put("type", "cq:Page");
searchCriteria.put("p.offset", offset.toString());
searchCriteria.put("p.limit", limit.toString());
searchCriteria.put("p.hits", "full");
searchCriteria.put("p.properties", "thumbnail");
searchCriteria.put("p.nodedepth", "2");
PredicateGroup predicateGroup = PredicateGroup.create(searchCriteria);
Query query = queryBuilder.createQuery(predicateGroup, session);
SearchResult result = query.getResult();
for (Hit hit : result.getHits()) {
try {
ValueMap properties = hit.getProperties();
VFSearchResult res = new VFSearchResult();
res.setUrl(hit.getPath());
res.setImageUrl((String)properties.get("thumbnail"));
res.setTags((String[])properties.get("cq:tags"));
res.setTeaserText((String)properties.get("teaserText"));
res.setTitle((String)properties.get("jcr:title"));
searchResults.add(res);
} catch (RepositoryException rex) {
logger.debug(String.format("could not retrieve node properties: %1s", rex));
}
}
After setting the path in the query, then set one or more property filters, such as in this example:
type=cq:Page
path=/content/path/to/articles
property=jcr:content/thumbnail
property.operation=exists
p.hits=selective
p.properties=jcr:content/thumbnail someSpecificThumbnailPropertyToRetrieve
p.limit=100000
You can set those on /libs/cq/search/content/querydebug.html and then also use that to get the JSON URL for the same query.
Check this out for some other examples: http://dev.day.com/docs/en/cq/5-5/dam/customizing_and_extendingcq5dam/query_builder.html
You could use CURL to retrieve node properties in the HTML/ JSON/ XML format. All you have to do is install download CURL and run your curl commands from your terminal from the same directory as the curl's .exe file.
HTML example:
C:\Users\****\Desktop>curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html
JSON example:
**C:\Users\****\Desktop>**curl -u username:password http://localhost:4502/content/geometrixx-media/en/gadgets/leaps-in-ai.html.tidy.infinity.json
Note: infinity in the above query ensures you get every property of every node under your specified path recursively

Mojolicious::Lite with Template Toolkit

I'm trying to get Template Toolkit to work as the default renderer in Mojolicious::Lite. What I have:
use strict;
use warnings;
use Mojolicious::Lite;
use Mojolicious::Plugin::TtRenderer;
plugin tt_renderer => { template_options => { INCLUDE_PATH => './tmpl', DEBUG => 1 } };
get '/' => sub {
my $self = shift;
$self->render( 'index' );
};
app->renderer->default_handler( 'tt' );
app->start;
When I try to hit the test server, I get:
[Fri Oct 12 14:02:02 2012] [info] Listening at "http://*:3000".
Server available at http://127.0.0.1:3000.
[Fri Oct 12 14:02:08 2012] [debug] Your secret passphrase needs to be changed!!!
[Fri Oct 12 14:02:08 2012] [debug] GET / (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20100101 Firefox/16.0).
[Fri Oct 12 14:02:08 2012] [debug] Routing to a callback.
[Fri Oct 12 14:02:08 2012] [debug] Nothing has been rendered, expecting delayed response.
This happens regardless of what I pass as parameters to 'render'. I can't seem to figure out how to get any useful debugging information out of this; but I haven't used Mojo before.
I've confirmed by sprinkling in some warn statements that my get handler is being called.
After looking at the source of Mojolicious::Plugin::TtRenderer::Engine, I figured it out. The plugin ignores the INCLUDE_PATH option passed to Template Toolkit, and instead gets the path from $app->renderer_paths. So updating my code to include:
app->renderer->default_handler( 'tt' );
app->renderer->paths( [ './tmpl' ] );
makes it work.

Rails I18n locale set date format in Rails

My environment: rails => 3.0.6, ruby => 1.9.2
I set my locale to Italan. Infact, inside the console
I18n.locale # => :it
My locale file work just fine, but I'cant make my dates display right. For ex. in my console
Date.current => Sun, 05 Jun 2011
instead of
05 Giugno 2011
But if I try other methods it return the right translated output
helper.number_to_currency(30) # => "30.00 €"
Locale issue occurs only with dates. Why?
Date.current => Sun, 05 Jun 2011
Won't run your code through the localizer, you should use
I18n.localize(Date.current)
I18n.l(Date.current)
There are also the helper methods in Rails, which will respect the locale, but are only (typically) available in the view, documentation for these lives here: http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html
Here's a short excerpt from an IRB session in a Rails 3.0.7 application (I don't have the other locales available)
ruby-1.9.2-p180 :001 > Date.current
=> Sun, 05 Jun 2011
ruby-1.9.2-p180 :002 > I18n.locale
=> :en
ruby-1.9.2-p180 :003 > I18n.l(Date.current)
=> "2011-06-05"
ruby-1.9.2-p180 :004 > I18n.locale = :ru
=> :ru
ruby-1.9.2-p180 :005 > I18n.l(Date.current)
=> I18n::MissingTranslationData: translation missing: ru.date.formats.default
Try
I18n.localize(Date.today)
or in the view just
l(Date.today)
Source:
http://guides.rubyonrails.org/i18n.html#adding-date-time-formats