Set up Flume HTTP agent on a URL? - hadoop

I've been able to set up my HTTP source on a host and port like:
agent.sources=s1
...
agent.sources.s1.type=http
agent.sources.s1.bind=0.0.0.0
agent.sources.s1.port=5140
And I can, for example, POST a json document to it via:
curl -X POST -H 'Content-Type: application/json; charset=UTF-8' -d '[{
"headers" : { "ip" : "192.168.1.102", "host" :
"random_host.example.com" }, "body" : "random_body" }, { "headers" : {
"ip" : "192.168.1.102", "host" : "random_host.example.com" }, "body" :
"really_random_body" }]' http://hostname:port
However I would like to be able to POST a Json document to http://hostname.com:port/a/b/c/
How may I do this?

Related

Why do I have to PUT new documents to a nested URI, if mapping types have been removed?

I'm on Elasticsearch 7.14.0 where mapping types have been removed.
If I run the following:
curl -X PUT "localhost:9200/products/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "Toast"
}
'
I get
{
"error" : "Incorrect HTTP method for uri [/products/1?pretty] and method [PUT], allowed: [POST]",
"status" : 405
}
It seems that elastic wants me PUT it in an /index/type/ URI:
curl -X PUT "localhost:9200/pop/products/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "Toast"
}
'
{
"_index" : "pop",
"_type" : "products",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
I am wondering why I must have a nested URI indicating a type, if mapping types have been removed?
You have to add _doc to your put request call as shown below
curl -X PUT "localhost:9200/products/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "Toast"
}
'
As mentioned in elasticsearch official documentation after mapping types were removed in 7.x, you need to add , _doc (which does not represent a document type rather it represents the endpoint name) for the document index, get, and delete APIs

Hasura: Change permissions/schema in Hasura on runtime (dynamically) through API call

I'm trying to change permissions in Hasura on runtime (dynamically) through API call as follows:
curl --location --request POST 'https://hasura-0ccfcde0.nhost.app/v1/query' \
--header 'x-hasura-role: admin' \
--header 'Content-Type: application/json' \
--data-raw '{
"type" : "create_update_permission",
"args" : {
"table" : "customers",
"role" : "users",
"permission" : {
"check" : {
"user_id" : {
"_ne": ""
}
},
"filter" : {
"user_id" : "X-Hasura-User-Id"
},
"set":{
"name":"X-Hasura-User-Id"
},
"columns":["name","email"]
}
}
}'
But it returns with
{
"path": "$.args",
"error": "restricted access : admin only",
"code": "access-denied"
}
I'm following: https://hasura.io/docs/1.0/graphql/core/api-reference/schema-metadata-api/permission.html#create-update-permission
as you can see in the screenshot as well
It's not enough for you to just put admin in the x-hasura-role Header. If you think about it, this would be a huge vulnerability as anyone could issue this request against your backend. You've even shared the endpoint here in your example CURL request!
Instead, you need to pass the x-hasura-admin-secret Header with the value you've configured for your deployment. This value should be extremely guarded as anyone who has access to it has pretty wide open access to Hasura and potentially your entire Database at that point depending on what your Hasura configuration looks like
curl --location --request POST 'https://hasura-0ccfcde0.nhost.app/v1/query' \
--header 'x-hasura-admin-secret: whatever-your-configured-admin-secret-is' \
--header 'Content-Type: application/json' \
--data-raw '{
"type" : "create_update_permission",
"args" : {
"table" : "customers",
"role" : "users",
"permission" : {
"check" : {
"user_id" : {
"_ne": ""
}
},
"filter" : {
"user_id" : "X-Hasura-User-Id"
},
"set":{
"name":"X-Hasura-User-Id"
},
"columns":["name","email"]
}
}
}
Alternatively, making a call with a JWT that is signed with the admin role could also work if you don't want to directly use your Hasura secret. In this case you would set it in the Authorization header with the x-hasura-role: admin claim set

How to pass Authorisation token for all elasticsearch requests

I've setup a local elasticsearch node with kibana and have set
xpack.security.enabled: true
I require this as i plan to further add roles and I want to add document level security.
Both Kibana & Elastic search are up and running at their respective ports. I am struggling to understand how to I add a new document operating via console.
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Content-Type: application/json' -d'
{
"name": "John Doe"
}
'
This fails with
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "missing authentication credentials for REST request [/customer/_doc/1?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
}
],
"type" : "security_exception",
"reason" : "missing authentication credentials for REST request [/customer/_doc/1?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
},
"status" : 401
}
Fair , I understand I need to get an auth token to pass to the curl. Which API retrives this and where can i find an example. I've tried this unsucessfully.
curl -X POST "localhost:9200/_security/oauth2/token?pretty" -H 'Content-Type: application/json' -d'
{
"grant_type" : "client_credentials"
"username" : "elastic",
"password" : "VKZjNLBVBSeLS08sHDIN"
}
'
The password was generated automatically while bringing up the node.
Thanks!
By curl:
curl -X PUT --basic -u {user}:{password} http://localhost:9200/customer/_doc/1?pretty
By http request in program:
1. Make the the base64 encoding for the string: ${user}:${password}
2. Add http header
key:"Authorization"
value:"Basic ${encode value in step 1}"
By curl with header:
curl -X PUT "localhost:9200/customer/_doc/1?pretty" -H 'Authorization:Basic ********' -H 'Content-Type: application/json' -d'
{
"name": "John Doe"
}
******** is the value of base64 encoding for the string: ${user}:${password}

How can curl perform a get request with a data payload?

The introductory materials on ElasticSearch include the following example curl request:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"query_string" : {
"query" : "(new york city) OR (big apple)",
"default_field" : "content"
}
}
}
'
This request has two parameter which I thought were incompatible:
-X GET, which specifies that the request is a GET.
-d [...], which specifies that the request has a data payload.
I thought that specifying a data payload was only possible in a PUT or POST requests, because GET requests do not have any concept of a data payload. Is this a valid curl command? What does it do, exactly?
Above curl request is a valid request, in fact, if you have index and data, then you can check the output of your command.
I tried it in my system and ES index and it gave me proper response.
curl -v -X GET "localhost:9500/querytime/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"query_string" : {
"query" : "(avengers) OR (big apple)",
"default_field" : "movie_name"
}
}
}'
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9500 (#0)
> GET /querytime/_search?pretty HTTP/1.1
> Host: localhost:9500
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 156
>
* upload completely sent off: 156 out of 156 bytes
< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-length: 905
<
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 0.14874382,
"hits" : [
{
"_index" : "querytime",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.14874382,
"_source" : {
"movie_name" : "Avengers: Infinity War"
}
}
]
}
}
As mentioned in the official manual of curl command, if you are using *nix based system, then you can search below in the manual of curl.
-G, --get
When used, this option will make all data specified with -d, --data, --data-binary or --data-urlencode to be used in an
HTTP GET request instead of the POST request that otherwise would be
used. The
data will be appended to the URL with a '?' separator
As explained in this SO answer, it also depends on the web-server to parse the body in GET request.

action [clustering/cluster] is unauthorized for user [elastic]

Elasticsearch has three nodes in my cluster, I am using plugin elasticsearch-carrot2, and elastic is a superuser in elasticsearch.
The requests I sent is below:
curl -XPOST --user elastic:**** -H "Content-Type: application/json"
'http://ip:port/index/type/_search_with_clusters?pretty=true' -d '
{
"search_request": {
"_source" : [
"title",
"body"
],
"query" : {
"match" : {
"title" : "something"
}
},
"size": 100
},
"query_hint": "something",
"field_mapping": {
"title" : ["_source.title", "_source.body"]
}
}'
Unfortunately I get following error:
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "action [clustering/cluster] is unauthorized
for user [elastic]"
}
],
"type" : "security_exception",
"reason" : "action [clustering/cluster] is unauthorized for user
[elastic]"
},
"status" : 403
}
The problem comes from the fact that the plugin doesn't work with XPack security.
More info can be seen in this issue: https://github.com/carrot2/elasticsearch-carrot2/issues/69

Resources