I'd like to set rateLimit for requests where in json data present param with sample value
Example
curl -X 'POST' 'http://127.0.0.1/' -H Host:whoami.docker.localhost -H 'accept: application/json' -H 'Content-Type: application/json' -d '{
"sender": "Tester",
"receiver": [
"receiver1"
],
"text": "Text",
"service": "service"
}'
I need limit 100rps for sender=Tester, other senders must have no rateLimit
I tried such config:
[http.routers]
[http.routers.whoami_1]
rule = "Host(`whoami.docker.localhost`)&&Query(sender=Tester)"
service = "whoami"
entrypoints = ["web"]
middlewares = ["test-ratelimit"]
[http.middlewares]
[http.middlewares.test-ratelimit.rateLimit]
average = 100
But received
404 page not found
How can I get param from json data in request and set rule for routes or middleware?
Traefik does not provide middlewares to extract the JSON payload from the request.
You can probably try to create a custom plugin extracting the value and applying the rate limiting on its own.
Related
I can't manage to push an image to a private registry using the docker API. I have read everything I found everywhere and tried everything with no luck...
I tried :
curl -X POST -H "X-Registry-Auth:XXXXXXXXXXXXXXX" http://dockerapiurl:2375/images/registryurl/python/push?tag=6
OR
curl -X POST -H 'X-Registry-Auth:{"username": "xxxxxx","password": "xxxxx", "serveraddress": "xxxx.url.net", "auth": ""}' http://dockerapiurl:2375/images/registryurl/python/push?tag=6
I always get the same error :
{"errorDetail":{"message":"errors:\ndenied: requested access to the resource is denied\nunauthorized: authentication required\n"},"error":"errors:\ndenied: requested access to the resource is denied\nunauthorized: authentication required\n"}
If I use docker push in CLI mode everything works, what am I doing wrong?
Thanks!!
it needs to be encoded in base 64, try this
XRA=`echo "{ \"username\": \"xxxxxx\", \"password\": \"xxxxxx\", \"email\": \"youmail#example.org\", \"serveraddress\": \"xxxxxx\" }" | base64 --wrap=0`
curl -X POST -d "" -H "X-Registry-Auth: $XRA" http://dockerapiurl:2375/images/registryurl/python/push?tag=6
end result should look like this
curl -X POST -d "" -H "X-Registry-Auth: eyAidXNlcm5hbWUiOiAieHh4eHh4IiwgInBhc3N3b3JkIjogInh4eHh4eCIsICJlbWFpbCI6ICJ5b3VtYWlsQGV4YW1wbGUub3JnIiB9Cg==" http://dockerapiurl:2375/images/registryurl/python/push?tag=6
I am following this documentation. I am able to get cluster's information like this:
curl -sk -X GET "https://xx.xx.xx.xx:8443/v3/clusters/"
the previous request works fine. However, when I try to create a topic I get HTTP 415 Unsupported Media Type javax.ws.rs.NotSupportedException error
command:
curl -sk -X POST \
-H "Content-Type: application/json" \
-d "{\"topic_name\":\"test1\",\"partitions_count\":6,\"replication_factor\":3,\"configs\":[]}" \
"https://xx.xx.xx.xx:8443/v3/clusters/xxxxxxx/topics"
does anyone have an idea on how to solve this issue?
I had the same issue, this worked for me.
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json"
--data '{"records":[{"value":{"foo":"bar"}}]}' "https://localhost:8443/topics/test"
The example from this blog post worked for me:
POST http://localhost:8443/v3/clusters/<CLUSTER_ID>/topics
Content-Type: application/vnd.api+json
{
"data": {
"attributes": {
"topic_name": "topic",
"partitions_count": 1,
"replication_factor": 2,
"configs": []
}
}
}
So changing the Content-Type to application/vnd.api+json and using a different request body
I'm using IoTAgent over MQTT configuration. After going step by step with the tutorial presented on FIWARE's website is there a way to invoke command using measurment input of the IoT Agent?
Let's say i have 2 arduinos: one is an actuator and the other one is a sensor. The actuator has LED attached, sensor has a button. I want to send a message from sensor-arduino with command ON (to MQTT Broker or directly as an Ultralight message via HTTP - as far as I tested IoTA for Ultralight can run simultaneously both modes which is great) what will invoke sending the command defined for given device.
Let's say im using this config:
curl -iX POST \
'http://localhost:4041/iot/devices' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"devices": [
{
"device_id": "bell001",
"entity_name": "urn:ngsi-ld:Bell:001",
"entity_type": "Bell",
"protocol": "PDI-IoTA-UltraLight",
"transport": "MQTT",
"commands": [
{ "name": "ring", "type": "command" }
],
"static_attributes": [
{"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
]
}
]
}
'
I can invoke command like this (which is very inconvenient):
curl -iX POST \
'http://localhost:4041/v1/updateContext' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"contextElements": [
{
"type": "Bell",
"isPattern": "false",
"id": "urn:ngsi-ld:Bell:001",
"attributes": [
{ "name": "ring", "type": "command", "value": "" }
],
"static_attributes": [
{"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
]
}
],
"updateAction": "UPDATE"
}'
Or after registering the command, I can use Orion Context Broker:
curl -iX PATCH \
'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:001/attrs' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"on": {
"type" : "command",
"value" : ""
}
}'
Those approaches give me a response in Mosquitto subscriber.
How can I create a message sent to IoTAgent (via MQTT or HTTP) that will invoke command sent to MQTT Broker? The command is further managed in actuator-arduino as long as is received in the MQTT Broker.
Using the IoT Agent North Port
I can invoke command like this (which is very inconvenient):
This is a command direct to the North Port of the IoT Agent itself - as the tutorial states it should only be used for testing the connectivity. You should never need to do this yourself - this is the command the Orion Context Broker sends to the IoT Agent
Using NSGI v2
Or after registering the command, I can use Orion Context Broker:
Using the PATCH command is the way to go - pre-registration of commands is not necessary in the more recent releases of the IoT Agent Library.
How to use FIWARE to send Commands to Arduino
How can I create a message sent to IoTAgent (via MQTT or HTTP) that will invoke the command sent to MQTT Broker? The command is further managed in actuator-arduino as long as is received in the MQTT Broker.
The context broker is merely receiving changes of context and informing subscribed services. Within the tutorial an NSGI v2 PATCH request is programmatically sent to the Context Broker using an HTTP request :
https://github.com/FIWARE/tutorials.Step-by-Step/blob/master/context-provider/controllers/ultraLight.js
const options = {
method: 'PATCH',
url: UL_CONTEXT_BROKER + '/entities/' + UL_NGSI_PREFIX + id + '/attrs',
headers: {
'Content-Type': 'application/json',
'fiware-servicepath': '/',
'fiware-service': 'openiot'
},
body: payload,
json: true
};
request(options, error => {
if (error) {
debug(error);
}
});
With a configured IoT Agent the result will be a topic posted to the MQTT broker.
There needs to be some code in the device to ensure it is subscribed to the right topic and then receive the payload.
https://github.com/FIWARE/tutorials.Step-by-Step/blob/master/context-provider/iot.js
const mqtt = require('mqtt');
const apiKey = process.env.DUMMY_DEVICES_API_KEY || '1234';
const topics = '/' + apiKey + '/#';
const mqttBrokerUrl = process.env.MQTT_BROKER_URL || 'mqtt://mosquitto';
global.MQTT_CLIENT = mqtt.connect(mqttBrokerUrl);
MQTT_CLIENT.on('connect', () => {
debug('Subscribing to MQTT Broker: ' + mqttBrokerUrl + ' ' + topics);
MQTT_CLIENT.subscribe(topics);
MQTT_CLIENT.subscribe(topics + '/#');
});
mqtt.connect(mqttBrokerUrl);
MQTT_CLIENT.on('message', function(topic, message) {
// message is Buffer
Ultralight.processMqttMessage(topic.toString(), message.toString());
});
I am using Icinga Version 2.4.2 to monitor services on several hosts. I would like to be able to place certain hosts in maintenance mode for a set amount of time using a cli tool or rest API instead of the Web UI.
Is this possible and if so what tool/api should I use?
If I cannot do this through a remote tool/api what command should I use on the server or client to place clients in maintenance mode?
Update: It seems like the rest api has a solution. This set of permissions works:
object ApiUser "root" {
password = "foobar"
permissions = [ "console", "objects/query/Host", "objects/query/Service", "actions/schedule-downtime", "actions/remove-downtime"]
}
Then the following allows me to make and remove downtimes:
curl -k -s -u root:foobar -H 'Accept: application/json' -X POST "https://localhost:5665/v1/actions/schedule-downtime?filter=host.name==%22${TARGET}%22&type=Host" -d '{ "start_time": "1528239116", "end_time": "1528325561", "duration": 1000, "author": "root", "comment": "downtime on $TARGET" }' | jq .
curl -k -s -u root:foobar -H 'Accept: application/json' -X POST "https://localhost:5665/v1/actions/remove-downtime?filter=host.name==%22${TARGET}%22&type=Host" | jq .
Right now the only issue with this I am having is how to pass in variables for the start and stop dates. Attempting this keeps resulting in the following error:
{
"status": "Invalid request body: Error: lexical error: invalid char in json text.\n { \"start_time\": $current_time,\n (right here) ------^\n\n",
"error": 400
}
I am requesting for authentication/authorization token using curl command like following:
curl -H "Content-Type: application/json" -d'{
"grant_type" : "authorization_code",
"code" : "4/bA5MjGf4emw3hkhCVuTZeJUjughQgJ21l-dCyfpPHdg",
"client_id" : "757054420263-0ajoc014s2dn91b8iko0vj2jtl5pdjfh.apps.googleusercontent.com",
"client_secret" : "xMElPZXcU-ajMUNUwKTksKpV",
"redirect_uri" : "https://www.googleapis.com/auth/cloud-platform"
}' https://accounts.google.com/o/oauth2/token
But it gives me following error:
{
"error" : "invalid_request",
"error_description" : "Required parameter is missing: grant_type"
}
And can I use this token for accessing API.
You need to POST the data as form-encoded parameters instead of POSTing them as JSON, so:
curl -d "grant_type=authorization_code" -d "code=4/bA5MjGf4emw3hkhCVuTZeJUjughQgJ21l-dCyfpPHdg" -d "client_id=757054420263-0ajoc014s2dn91b8iko0vj2jtl5pdjfh.apps.googleusercontent.com" -d "client_secret=xMElPZXcU-ajMUNUwKTksKpV" -d "redirect_uri=https://www.googleapis.com/auth/cloud-platform" https://accounts.google.com/o/oauth2/token