How to remove a consul service endpoint / id? - consul

If I have registered two "endpoints" for a service like so:
curl -X PUT -d '{"ID": "app1", "Name": "app", "Address": "1.2.3.4", "Port": 3000}' http://127.0.0.1:8500/v1/agent/service/register
curl -X PUT -d '{"ID": "app2", "Name": "app", "Address": "5.6.7.8", "Port": 3000}' http://127.0.0.1:8500/v1/agent/service/register
How can I later delete a specific endpoint - for example the second (with ID app2?
Reading thruogh https://www.consul.io/api/agent/service.html I can only find a way to delete the entire service

http://127.0.0.1:8500/v1/agent/service/deregister/${ID_GOES_HERE}
So in the above example
curl -X PUT http://127.0.0.1:8500/v1/agent/service/deregister/app2

Related

Postman gives me the following error: "error": "no handler found for uri [/megacorp/employee/1] and method [PUT]"

I am just starting with Elasticsearch and I have started with adding an index, which works and I can get information about it:
GET http://localhost:9200/megacorp
"megacorp": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"routing": {
"allocation": {
"include": {"_tier_preference": "data_content"
}
}
},
"number_of_shards": "1",
"provided_name": "megacorp",
"creation_date": "1657286196414",
"number_of_replicas": "1",
"uuid": "HbsAAv-mRziSUKGiXPMyPA",
"version": {
"created": "8030299"
The problem comes when I try to add a document, I get the following error:
PUT http://localhost:9200/megacorp/empoyee/1
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": ["sports", "music"]
"error": "no handler found for uri [/megacorp/empoyee/1] and method [PUT]"
I think I've done everything right, but it still does not work.
Problem here, that you are using wrong URL in your request.
According to documentation you must use use following paths for document index:
Request
PUT /<target>/_doc/<_id>
POST /<target>/_doc/
PUT /<target>/_create/<_id>
POST /<target>/_create/<_id>
So you are missing _doc or _create part.
UPDATE:
cURL Example
curl -X PUT --location "http://localhost:9200/megacorp/1" \
-H "Content-Type: application/json" \
-d "{
\"first_name\": \"John\",
\"last_name\": \"Smith\",
\"age\": 25,
\"about\": \"I love to go rock climbing\",
\"interests\": [\"sports\", \"music\"]
}"
From elasticsearch 8.x mapping types are removed. You need to use this for indexing the documents
http://localhost:9200/megacorp/_doc/1

How to send a hyperlink in a incoming-webhook message?

I know I can use html and markdown in my incoming webhook, but when I try to embed a link, it does not work. Need help, please
curl -H "Content-Type: application/json" -d "{\"text\": \"<a href=' www.microsoft.com'>visit</a >\"}" <my webhook url>
curl -H "Content-Type: application/json" -d "{\"text\": \"[visit](www.microsoft.com)\"}" <my webhook url>
Standard markdown can be used:
curl --header "Content-Type: application/json" \
--data "{\"text\": \"[visit](https://www.microsoft.com)\"}" \
<my webhook url>
Note that OP omitted the URI scheme, which prevents Teams from identifying the URL as a valid one.
I got the similar issue before, and I found I could use adaptive cards. It's much more powerful! Below is the sample payload.
{
"#type": "MessageCard",
"#context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "a summary",
"sections": [{
"activityTitle": "A title",
"activitySubtitle": "a subtitle",
"markdown": true
}],
"potentialAction": [{
"#type": "ActionCard",
"name": "Visit",
"actions": [{
"#type": "OpenUri",
"name": "Visit",
"targets": [
{ "os": "default", "uri": "https://www.microsoft.com" }
]
}]
}]
}

parse_exception - request body is required

I'm trying to insert a JSON data file in my elasticsearch instance.
curl -s -H “Content-Type: application/x-ndjson” -XPOST localhost:9200/_bulk —-data-binary “#restaurants.json”; echo
However, after executing this command I get an error that says
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}
The JSON file basically has an array of the below object.
Only thing is that I've put just one object here to save space. However, there are more than one objects present.
Structure is like given below;
[
{
"address": {
"building": "351",
"coord": [
-73.98513559999999,
40.7676919
],
"street": "West 57 Street",
"zipcode": "10019"
},
"borough": "Manhattan",
"cuisine": "Irish",
"name": "Dj Reynolds Pub And Restaurant",
"grades": [
{
"date": {
"$date": "2014-09-06T00:00:00.000Z"
},
"grade": "A",
"score": 2
},
{
"date": {
"$date": "2013-07-22T00:00:00.000Z"
},
"grade": "A",
"score": 11
},
{
"date": {
"$date": "2012-07-31T00:00:00.000Z"
},
"grade": "A",
"score": 12
},
{
"date": {
"$date": "2011-12-29T00:00:00.000Z"
},
"grade": "A",
"score": 12
}
],
"id": "30191841"
}
]
The bulk API requires one document per line, which means you can't have newlines in your documents. Try stripping all the white spaces from the JSON you're submitting. You are also just submit a stream of documents, and not a JSON array of objects. See Bulk API documentation here: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
I had this same issue in Windows and am posting this here for anyone that comes across the same question with this error referenced.
{"error":{"root_cause":[{"type":"parse_exception","reason":"request body is required"}],"type":"parse_exception","reason":"request body is required"},"status":400}
I found at least two causes:
cURL doesn't know where the file you are trying to load is:
In this case, make sure to run cURL from the directory where the file is located. Try executing the following command and making sure you see the file.
more file.json
Windows command line DOES NOT support single quotes within the cURL command line:
BAD
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk' --data-binary '#file.json'
GOOD
curl -H "Content-Type: application/x-ndjson" -XPOST "localhost:9200/_bulk" --data-binary "#file.json"
I solved it by wrapping the url with quotation mark.
curl -s -H “Content-Type: application/x-ndjson” -XPOST "localhost:9200/_bulk —-data-binary “#restaurants.json”;

Mesos Marathon deploy was failed when added parameters in Json file

I was trying to deploy ngnix docker container by mesos Marathon, I would like to set some environment variables in the container, so I added parameter section in the Json file, but after I added the parameter section, it was failed. My Json file as following:
{
"container":{
"type":"DOCKER",
"docker":{
"image":"nginx",
"network":"BRIDGE",
"portMappings":[{"containerPort":80,"hostPort":0,"servicePort":80,"protocol":"tcp"}],
"parameters": [
{ "key": "myhostname", "value": "a.corp.org" }
]
}
},
"id":"nginx7",
"instances":1,
"cpus":0.25,
"mem":256,
"uris":[]
}
my launch script was: curl -X POST -H "Content-Type: application/json" 10.3.11.11:8080/v2/apps -d#"$#"
The command I ran was: ./launch.sh nginx.json
You used the wrong parameter key myhostname, if you want to setup hostname for you container, it should be:
"parameters": [
{ "key": "hostname", "value": "a.corp.org" }
]
if you want to pass environment variable, it should be:
"parameters": [
{ "key": "env", "value": "myhostname=a.corp.org" }
]

Mesos : Unreserve slaves resources

Is there any way to reset all slaves reserved resources in Mesos, without configuring one by one the /unreserve http endpoint?
In Mesos documentation :
/unreserve (since 0.25.0)
Suppose we want to unreserve the resources that we dynamically reserved above. We can send an HTTP POST request to the master’s /unreserve endpoint like so:
$ curl -i \
-u <operator_principal>:<password> \
-d slaveId=<slave_id> \
-d resources='[
{
"name": "cpus",
"type": "SCALAR",
"scalar": { "value": 8 },
"role": "ads",
"reservation": {
"principal": <reserver_principal>
}
},
{
"name": "mem",
"type": "SCALAR",
"scalar": { "value": 4096 },
"role": "ads",
"reservation": {
"principal": <reserver_principal>
}
}
]' \
-X POST http://<ip>:<port>/master/unreserve
Mesos doesn't directly provide any support for unreserving resources at more than one slave using a single operation. However, you can write a script that uses the /unreserve endpoint to unreserves the resources at all the slaves in the cluster, e.g., by fetching the list of slaves and reserved resources from the /slaves endpoint on the master (see the reserved_resources_full key).

Resources