How to apply filters with qpid proton against azure event hubs - amqp

I am trying to apply a filter with qpid-proton-0.17.0 against azure eventhubs. Here is my filter code:
proton::value filter_value;
proton::codec::encoder enc(filter_value);
enc << proton::codec::start::described()
<< proton::symbol("apache.org:selector-filter:string")
<< proton::binary("amqp.annotation.x-opt-offset > '100'")
<< proton::codec::finish();
proton::source::filter_map map;
proton::symbol key("apache.org:selector-filter:string");
map.put(key, filter_value);
proton::receiver_options ro;
ro.source(source_options().filters(map));
I get no messages back and eventually this error:
com.microsoft:timeout: The operation did not complete within the allocated time
00:01:00 for object attach.
If I apply no filter, I do get the unfiltered message stream to appear. I have been able to get the filter to work with similar javascript code in nodejs using noodlefrenzy's amqp10 library. Any help on how to get my qpid code to work would be appreciated.
New note: per Xin Chen's reply, I replaced the line above
<< proton::binary("amqp.annotation.x-opt-offset > '100'")
with
<< "amqp.annotation.x-opt-offset > 100"
And this seems to work.

The Azure Event Hubs uses a described string as a filter to specify start position. The descriptor is a symbol "apache.org:selector-filter:string" and the value is a string. More details can be found in this page: https://github.com/Azure/amqpnetlite/blob/master/docs/articles/azure_eventhubs.md

Related

Discord API - get messages before a date from a channel

I want to implement a command in my bot, to allow fetching messages from a channel and process them further.
I tried to look for how to fetch messages from a specific channel, but could not find an explicit answer to it, except most of the forum pages simply refer to the API page, with some saying trying the discord.utils.get method.
I am wondering if it would be something like this, but I could not find the matching methods/attributes that I can use to do this:
#bot.command(name='fetchmessages', help='....')
async def fetchmessages(ctx, from_channel_id:str, from_date:str):
#check if the channels already exist
channel = discord.utils.get(ctx.guild.channels, id=from_channel_id)
from_date = .... #code to parse the string to a date object
discord.utils.get(channel.messages, # Q1
from=from_date) # Q2
####
However, I cannot really do this because
Q1: assuming the channel is a TextChannel link, the class does not have an attribute that gives me all the messages from that channel, but only last_message. While TextChannel has a method fetch_message but that only gets a single message with an ID parameter
Q2: I am not sure if I can pass a date object like this, because the API for discord.utils.get does not explicitly say what attributes (**attrs) can be specified.
Any hints much appreciated.
Thanks
You are right that you can't use fetch_message because it only returns a single message, but you can use channel.history (link can be found here)
from datetime import datetime
#bot.command()
async def fetchmessages(ctx, from_channel_id:str, from_date:str):
channel = client.get_channel(int(from_channel_id))
date = datetime.strptime(from_date, '%b %d %Y %I:%M%p')
messages = await ctx.channel.history(limit=200, after=date).flatten()
#To do something with messages
Referenced this question regarding string to datetime object.
Q1: you can use the channel.history() function but for that, you would have to have the read_message_history permissions to get access to those messages
Q2: as you can read in discord.utils.get "To have a nested attribute search (i.e. search by x.y) then pass in x__y as the keyword argument." you can access whatever variable you want but instead of using '.' you need to use '_'
so for example
discord.utils.get(channel.messages,created_at=from_date)
another thing that I just want to point out is the date attribute you're trying to get by has to be a datetime.datetime object

Rsyslog omprog pass message to scripts

Accurately, I want to filter logs and send some warning email.
Firstly, I tried ommail, but unfortunately, this module only support mail server which do not need authentication, but my mail server needs.
So I tried to use omprog, I wrote a python script to logon to my mail server, it will recieve one parameter which is the log and send it as mail body.
Then I got the problem, I cannot pass the log to my script, if I try like this, $msg will be recognized as a string .
if $fromhost-ip == "x.x.x.x" then {
action(type="omprog"
binary="/usr/bin/python3 /home/elancao/Python/sendmail.py $msg")
}
I tried to search the official doc.
module(load="omprog")
action(type="omprog"
binary="/path/to/log.sh p1 p2 --param3=\"value 3\""
template="RSYSLOG_TraditionalFileFormat")
but in the sample, what they are using is a string "p1", not a dynamic parameter.
Can you please help? Thanks a lot!
The expected use of omprog is for your program to read stdin and there it will find the full default RSYSLOG_FileFormat template data (with date, host, tag, msg). This is useful, as it means you can write your program so that it is started only once, and then it can loop and handle all messages as they arrive.
This cuts down on the overhead of restarting your program for each message, and makes it react faster. However, if you prefer, your program can exit after reading one line, and then rsyslog will restart it for the next message. (You may want to implement confirmMessages=on).
If you just want the msg part as data, you can use template=... in the action to specify your own minimal template.
If you really must have the msg as an argument, you can use the legacy filter syntax:
^program;template
This will run program once for each message, passing it as argument the output of the template. This is not recommended.
if omprog script is not doing or not saving to a file the problem is that :
rsyslog is sending the full message to that script so you need to define or use a template
your script needs to listen to and return an
example in perl whit omprog
#my $input = join( '-', #ARGV ); ///not working I lost 5 hours of my life
my $input = ; now this is what you need
Hope this what the perl/python/rsyslog community needs.

Google Tasks API does not give update about Task completion when New Gmail Theme used

First I created a Task using below link:
https://mail.google.com/tasks/canvas
Then I marked it as Completed. When I checked the API Response for the same using:
Services > Tasks API v1 > tasks.tasks.list [Returns all tasks in the specified task list.]
I was able to view the updates & found the task i marked as complete.
However when I did the same using New interface (theme) from GMail, I found that the task I updated with completion was not at all there in above API Response.
Thus Google Tasks API does not give update about Task completion when New Gmail Theme used. Is there anything I missed or is it bug from Google Task API with Newly introduced theme?
I was held up by this same thing this week. but I just figured it out using the "Try this API" feature on https://developers.google.com/tasks/v1/reference/tasks/list which I got to show me my completed tasks. After looking at how their code told tasks.tasks.list that they wanted to be given the completed and hidden items (both flags were needed) I played around with my code and learned from error messages that after giving the tasklist ID, I could add a JavaScript object literal, so I copied part of object literal from the code of the "Try this API" and the following worked.
var tasks = Tasks.Tasks.list( taskListId, { showCompleted: true, showHidden: true } );
if (tasks.items) {
for (var i = 0; i < tasks.items.length; i++) {
var task = tasks.items[i];
Logger.log('Task with title "%s" and notes "%s" and status "%s" was found ' ,
task.title, task.notes, task.status );
}
}

Get a message's ts value from /archives link

Slack has a Copy link feature, which copies a deep link to an individual chat message to the clipboard:
Here's an example of such a deep link (obfuscated):
https://myworkspace.slack.com/archives/CqwertGU/p1234567898000159
What I'd like to do is, get the details of that message from the Slack API given that link.
The first string after /archives/ is the channel's ID. I'm not quite clear about that second string though:
According to Slack's API documentation,
channels.history can also be used to pluck a single message from the
archive.
You'll need a message's ts value, uniquely identifying it within a
channel. You'll also need that channel's ID.
So, what I've found is that the p1234567898000159 value in the link above is almost the message's ts value, but not quite (the Slack API won't accept it): the leading p needs to be removed, also there has to be a . inserted after the 10th digit: 1234567898.000159
Putting all this together into an API request...
https://slack.com/api/channels.history?latest=1234567898.000159&channel=CqwertGU&count=1&pretty=1&token=mytoken123&inclusive=true
... I'm getting a response with all the message details, exactly what I need.
My question is: am I doing this right? Do I really need to craft the message's ts value from the URL parameter this way, or is there a better, more robust, officially supported way?
Im new in python, but i got same problem when i creating SlackBot (by SlackBolt), and i solved it like that:
link = 'https://***.slack.com/archives/C03UGEVQ6BX/p1668769293636169'
#Grab information from link
wrong_link_list = link.split('/')
wrong_ts = wrong_link_list[-1]
t_ts = wrong_ts.replace('p', '', 1)
dot = '.'
char_count = 10
#Put information in variables
channel = wrong_link_list[-2]
text = 'Hey dude!'
mess_ts = t_ts[:char_count] + dot + t_ts[char_count:]
app.client.chat_postMessage(channel=channel, text=text, thread_ts = mess_ts)
Hope this will help you!

How do I correlate two identically coded variables sent in the response from a Worklight server response string in LoadRunner 12.02?

I am trying to create a load test versus one of our apps that is used on web and mobile. I am trying to access this app from the web. I login to the website. Using this login, I click on the web version of the app. The below response is returned here.
This app is using SiteMinder and Worklight to negotiate with the main site I am coming from.
My question is, how do I correlate a value such as 'SMIDENTITY=' when it is being returned TWICE in the same string?
Here is an example of what is being returned by the server (I have broken up the string so the variables are separated:
Test4.c(225):
Cookie:testcookie=oreo;
SMIDENTITY=Cq16kwJwrJWgBd5zQ8ci0kP8IEZ47kftOxMr1wVsxx+W/7sGS92ZA9zu69GRpolh0PRX97bvfHRya0m1ty1E07qR0HjKKXE8ypRsWPgG4m2w8mlspPUxL8t5Z4RE5/CCJpOxpXHIHeQK4f77gkihKFq8cBQr+Vy9kZGFGMUJH6+EiLNmmJT+XYZcUi7gzV0r+naJypMewtXAYaOcvn8Kqsu2JA5SiNUcJbxxX4dNCHOsC4cf45Jm0H40Efq6nOwN7MDyAE2gXSou4oa9ZlYxlsvWdEVl6CxgnqnqEkBJYVuBsgj/277+F7q9KB4xpct/sYvRT9CR/Rvh79hmpJJedH+lA8A6UtqyA21CnECQJzrbKJJgx3eeyN86BQv3g/kOWJ2CE4txEn22U+AjMKmxgB7fmLTNdxKS5+sn9P/Fs+TGwhRSX3pr/l1h4NQpNz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a0g4huq457lH3CDLQF+jj8w9qB2/gSVlWXKX0SKHNd2YJ2mBrc4j7oBOE8GOXiJlH8B5qnKvX99aYIdKxXoNILDBfK/RFaGWIy34uLNVRjOkZcUkKCBVB0D83GIj2EM2YqFs+GuWnRKvW7woAGIN69j7T50NWoIF/TPmdCnCM1HEfxhHfqxK0u5PUKheZeKNXqepoNIEb5ry1QGBho0OAeXQvlYeXiPZfKknu66iJpPEQaIpj0csWThztytn7uDuAiTCPZ4Yhwm+6pYHhxp7Jx/U84L2u3M7BamqD+oiCrFaYpMXkCGHw99hbHhE1okP3q+Hb/TCODKwIG80lw7660Y+nFGMIaCreNeu0Em+dY7rTU+KubyJqeYtt/NssB1Qq945MShkhix+KDKE+ViNmmyRqyUQpTEx6fXgbJQihm7KguDfOJSxvsalaO3vAwwN/mJTSxcRVktIaAYT4ZcakZS5r/mLRVllQmOczO4Ex2zAgflcEZ3GUlG3+TuL6JCYVWI3haAa0wUWffLCYRPo/n2+4vl5v/x9HkTXIZe0p4JCS1nWpzZXsg==;
LtpaToken=EHYGd9YV18oZsd8vSkJGm6EitmZCspgF2RbWMb/kDol6urQ8ZBeespgw8VR0jXPkwKdnAQjJ5x4ZdmTexnZiL3QIVzdH+DwWbTNP4KBAe/cdizYf8/0w05B9N13YX4rT7xl/Y0ZUhZX1brNgM7zP19a4IjL0E0M5uK2qah9ggErQhovcziPkA6Uubd4ne5keV/H/S0ZdaRMSjhXp6njlRtJl6C2U5r91YTXYVnbnl+sgG88g9jnPa6+peg+yi4P9VeoSohydoAIrqBGbpr7yL9ocaO3dL6bq/Ff6WAWZuca1V+7+x4bxtWHQ2CgafibbAkowunOsCyHvCRbv2FH8MQ==;
JSESSIONID=0000QLn5MU6tB5uMM0bXlOC8ZYS:15b4l3mm8;
SITE_ENTRY_JUMPTO=polhome;
scoreboard="";
scoreboardReport="";
WLSESSIONID=0000Xr6ZS67VI4UH-HoycrnVBq1:18lm04lom\r\n
Use the Ordinal (or index) number of the instance of the variable which you need as part of your collection
See training material or online help for correlation functions related to ordinal value
You didn't say what you're actually trying to do. Do you need only use the most recent? only use the first?
You use a web_reg_save_param_ex to capture all Ordinals of a parameter. It puts it into an array.
You can then do what you want with that array.
You can also use a web_reg_save_param_regexp
I coped the code from the official documentation and put your variable name in there to make it easier for you.
web_reg_save_param_ex(
"ParamName=SMIDENTITY",
"LB/IC=SMIDENTITY=",
"RB/IC=;",
"Ordinal=all",
LAST);
web_submit_data("...");
/* Getting individual elements from a parameter array.
Since the parameter created by web_reg_save_param_ex
is called "SMIDENTITY", the number of elements
is saved in parameter "SMIDENTITY_count".
The array elements are parameters "SMIDENTITY_1",
"SMIDENTITY_2", ... "SMIDENTITY_n".
*/
elemCnt = atoi(lr_eval_string("{SMIDENTITY_count}"));
lr_output_message("Number of items found = %d",elemCnt);
for (x=1;x<=elemCnt;x++) {
sprintf(arrayParamName, "{SMIDENTITY_%d}", x);
lr_output_message ("%s: %s",
arrayParamName,
lr_eval_string(arrayParamName));
}

Resources