how openstacksdk get_port just through ip_address - port

How to get the special port information which only dependent on the ip-address field by openstacksdk API, like the result as the openstack-client tool show:
# openstack port list --fixed-ip ip-address=1.1.1.1
+-----+------+-------------+---------------------------------------+--------+
| ID | Name | MAC Address | Fixed IP Addresses | Status |
+-----+------+-------------+---------------------------------------+--------+
| f23 | | fa:*****:ad | ip_address='1.1.1.1', subnet_id='821' | ACTIVE |
+-----+------+-------------+---------------------------------------+--------+
I had try these methods, none work:
port = conn.network.get_port(openstack.network.v2.port.Port(fixed_ips=[{'subnet_id'" '821', 'ip_address': '1.1.1.1'}]))
err: openstack.exceptions.InvalidRequest: Request requires an ID but none was found
port = conn.network.ports(fixed_ips=[{'ip_address': '1.1.1.1'}])
err: openstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: domain:9696/v2.0/ports?fixed_ips=ip_address, Invalid input for operation: 'ip_address' is not of the form <key>=[value].
port = conn.network.ports(fixed_ips=['1.1.1.1'])
err: penstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: domain:9696/v2.0/ports?fixed_ips=1.1.1.1, Invalid input for operation: '1.1.1.1' is not of the form <key>=[value].
port = conn.network.ports(ip_address='1.1.1.1')
err: openstack.exceptions.BadRequestException: BadRequestException: 400: Client Error for url: https://gzi-ost.2980.com:9696/v2.0/ports?ip_address=1.1.1.1, ['ip_address'] is invalid attribute for filtering
Refer to these documentation: network.port-operations and openstack api list-ports-detail .
How could I achieve that? Thank you in advance.
One more thing, I couldn't know the port_id before, only know the fixed ip-address.

Obviously, my bad, the problem is that my request parameter has a wrong format data.
Solve it by import urllib to encode the request json data in Python 3.
conn.network.ports(fixed_ips=urllib.parse.urlencode({'ip_address': '1.1.1.1'}))
Returns: A generator of port objects.
or
conn.list_ports({'fixed_ips': urllib.parse.urlencode({'ip_address': '1.1.1.1'})})
Returns: A list of port munch.Munch.

Related

HAProxy 2.0 LUA Fetches API - how to get request details and how to pass variable back to HAProxy

I have been scouring the internet with no luck. I have a basic LUA script for HAProxy, which looks like this:
core.Info("LUA script for parsing request ID element - loaded");
function parseId(txn, salt)
local payload = txn.sf:req_body()
-- parses hex value from element named "ID". Example payload: {"Platform":"xyz.hu","RecipientId":"xyz.hu","Channel":"xyz","CallbackURL":"http://x.x.x.x:123","ID":"5f99453d000000000a0c5164233e0002"}
local value = string.sub(string.match(payload, "\"ID\":\"[0-9a-f]+\""), 8, -2)
core.Info("ID : " .. value)
return value
end
-- register HAProxy "fetch"
core.register_fetches("parseId", parseId)
What it does is what it says: takes a 32 characater long ID from an incoming request. In the HAProxy config file, the result is used for sticky-session handling:
stick-table type string len 32 size 30k expire 30m
stick on "lua.parseId" table gw_back
This produces two lines of log for each request:
ID: xyz which is logged from the LUA script
The detailed request data which is logged from the HAProxy config file using "log-format", e.g.:
Jan 20 22:13:52 localhost haproxy[12991]: Client IP:port = [x.x.x.x:123], Start Time = [20/Jan/2022:22:13:52.069], Frontend Name = [gw_front], Backend Name = [gw_back], Backend Server = [gw1], Time to receive full request = [0 ms], Response time = [449 ms], Status Code = [200], Bytes Read = [308], Request = ["POST /Gateway/init HTTP/1.1"], ID = [""], Request Body = [{"Platform":"xyz.hu","RecipientId":"xyz.hu","Channel":"xyz","CallbackURL":"http://x.x.x.x:123","ID":"61e9d03e000000000a0c5164233e0002"}]
I wanted to extend logging due to some strange issues happening sometimes, so I wanted to one (or both) of below approaches:
Pass the "ID" value back from the LUA script into the HAProxy config as a variable, and log it along with the request details. I can log the full request body, but don't want to due to GDPR and whatnot.
Get some request details in the LUA script itself, and log it along with the ID.
So, basically, to be able to connect the ID with the request details. If multiple requests are coming to same URL very quickly, it is difficult to find which of them belongs to a specific ID. However I couldn't accomplish these.
For the first one, I added this line into the LUA before returning the "value" variable:
txn:set_var("req_id", value)
I was hoping this would create a variable in HAProxy called "req_id", and I can log it with "log-format", but all I got was empty string:
ID = [""]
For the second one, I'm at a complete loss. I'm not able to find ANY documentation on these. I have been scouring the internet with no luck. E.g. the txn.sf:req_body() function which I know is working, I simply cannot find it documented anywhere, so I'm not sure what other functions are available to get some request details.
Any ideas for either or both of my approaches? I'm attaching my full HAProxy config here at the end, just in case:
global
log 127.0.0.1 len 10000 local2 debug
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
lua-load /opt/LUA/parseId.lua
stats socket /etc/haproxy/haproxysock level admin
defaults
log global
option httplog
option dontlognull
mode http
timeout connect 5000
timeout client 50000
timeout server 50000
# Request body is temporarily logged in test environment
log-format "Client IP:port = [%ci:%cp], Start Time = [%tr], Frontend Name = [%ft], Backend Name = [%b], Backend Server = [%s], Time to receive full request = [%TR ms], Response time = [%Tr ms], Status Code = [%ST], Bytes Read = [%B], Request = [%{+Q}r], ID = [%{+Q}[var(txn.req_id)]], Request Body = [%[capture.req.hdr(0)]]"
frontend gw_front
bind *:8776
option http-buffer-request
declare capture request len 40000
http-request capture req.body id 0
http-request track-sc0 src table gw_back
use_backend gw_back
backend gw_back
balance roundrobin
stick-table type string len 32 size 30k expire 30m
stick on "lua.parseId" table gw_back
# Use HTTP check mode with /ping interface instead of TCP-only check
option httpchk POST /Gateway/ping
server gw1 x.x.x.x:8080 check inter 10s
server gw2 y.y.y.y:8080 check inter 10s
listen stats
bind *:8774 ssl crt /etc/haproxy/haproxy.cer
mode http
maxconn 5
stats enable
stats refresh 10s
stats realm Haproxy\ Statistics
stats uri /stats
stats auth user:password

ms-graph to outlook: getting error "invalid filter clause"

I have a simple enough API request:
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=isRead eq false?$select=subject,body
But the returned JSON says "Invalid filter clause"
I've tried URL encoding (i.e. adding %20 for spaces): same result
Apparently there is a typo here and that's the reason why this error occurs:
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=isRead eq false?$select=subject,body
^
query options expects '&' instead of '?' as a delimiter
Here is a valid OData URL:
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$filter=isRead eq false&$select=subject,body
\_______________________________/\___________________________/ \__________________________________________/
| | |
service root URL resource path query options

401 Unauthorized Access while using Twilio's Programmable Chat

I am trying to create an iOS chat application using Twilio's Programmable Chat.
I am able to retrieve the token from Twilio by passing device token and identity, but I am getting the 401 unauthorized Access while loading the channels(if any). I have checked my Twilio credentials
TWILIO_ACCOUNT_SID
TWILIO_AUTH_TOKEN
TWILIO_API_KEY
TWILIO_API_SECRET
TWILIO_IPM_SERVICE_SID
and all of them are assigned properly.
This is my response which I received from Twilio.
json = ["identity": ved, "token": eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJkNTNmZGFjZDlmMWUwODA0OGZjOGE3MDU5ZTAyYTg1Zi0xNDk4NjY5Mjc1IiwiZ3JhbnRzIjp7ImlkZW50aXR5IjoidmVkIiwiaXBfbWVzc2FnaW5nIjp7InNlcnZpY2Vfc2lkIjoiSVMwNjYxMWUwNzE4M2U0NmVkOWE5ZWM1Yzg4ZGFhZmViNCIsImVuZHBvaW50X2lkIjoiQ2hhdFNlcnZpY2U6dmVkOnVuZGVmaW5lZCJ9fSwiaWF0IjoxNDk4NjY5Mjc1LCJleHAiOjE0OTg2NzI4NzUsImlzcyI6ImQ1M2ZkYWNkOWYxZTA4MDQ4ZmM4YTcwNTllMDJhODVmIiwic3ViIjoiQUMwYjI4OWViMGUwNTc2ZGU0NDNhMTkzYzdkZjk4YTg4OCJ9.LfSUM3v70Am3d3me6BQn7NC3T6mPggD9cikjf52Qvk8]
For reference, I am getting the below stackTrace in the console.
2017-06-28 22:33:18.705 twiliochat[1252:52536] TNNotificationClient[2]: 0x7000047ea000 | 06/28/22:33:18.704 | WARNING | 7 | TNNotificationClient | onTwilsockError: 0 - Poco exception while connecting: I/O error: Bad socket descriptor
2017-06-28 22:34:07.682 twiliochat[1252:52530] TNTransportConnectingState[3]: 0x7000044d8000 | 06/28/22:34:07.680 | INFO | 9 | TNTransportConnectingState | Leaving state: Transport connecting
2017-06-28 22:34:07.682 twiliochat[1252:53398] TNTwilsockClient[4]: 0x700004143000 | 06/28/22:34:07.680 | DEBUG | 1 | TNTwilsockClient | onMessageReceived (226)
TWILSOCK V1.0 160
{"method":"close","id":"TM43a26b096fb040dca4751bef7ca17dec","payload_size":43,"payload_type":"application/json","status":{"code":401,"status":"Not authorized"}}
{"code":401,"status":"Authorization error"}
Few Notes to consider before answering this thread :
I have set up my server properly and I am doing ngrok also.
I am using node.js for server setup.
Twilio developer evangelist here.
It looks like you are using your auth token instead of your API Key when generating your access token.
Make sure you are instantiating the Access Token like this:
const accessToken = new AccessToken(
context.TWILIO_ACCOUNT_SID,
context.TWILIO_API_KEY,
context.TWILIO_API_SECRET
);
The API Key should start "SK..."
Just as a precaution, since your auth token has been exposed you should change that in your Twilio console.
Let me know if that helps at all.

How to check if files exist from list of urls in Google Spreadsheet?

Assume that I have a list of URLs, each URL returns code 200 or 404.
How can I extract HTTP response code from these URLs?
Is there a function like importHTML, but it checks response code only?
|A |B |
-+-------------------------------+------------------------+
1|URL |response code |
-+-------------------------------+------------------------+
2|http://example.com/huge1.tar.gz|=importHTMLResponse($A2)|
3|http://example.com/huge2.tar.gz|=importHTMLResponse($A3)|
4|http://example.com/huge3.tar.gz|=importHTMLResponse($A4)|
...
You would have to right a proxy service to a known url then
importHTMLResponse(http://MYPROXYSERVER/reponsecode?url=$A2)
or something similar.
The proxy service would run what ever language you are comfortable with and just hit the supplied url returning the status code.

Get Request from happstack-lite API

How would I go about getting the Request data from the happstack-lite API? I'm trying to get the client's IP address. From what I can tell it's in Request::rqPeer, and I get confused trying to dive into the monadic-layers of the happstack API.
You can use askRq in any ServerMonad to get at the Request, which you could pattern match on with record syntax to get the client hostname:
do Request {rqPeer = (host,_)} <- askRq
ok $ "Your IP: " ++ host

Resources