I have a URL which returns a list of tasks for my applicaiton.
Request: /marathon/v2/apps/myapplication/tasks/
Response: {"tasks":[{"ipAddresses":[{"ipAddress":"172.17.0.3","protocol":"IPv4"}],"stagedAt":"2018-03-19T15:38:59.486Z","state":"TASK_RUNNING","ports":[22660],"startedAt":"2018-03-19T15:39:05.571Z","version":"2018-03-19T15:38:59.157Z","id":"myapplication.a47c2cd2-2b8b-11e8-a2bb-0e25310fd094","appId":"/myapplication","slaveId":"d0207878-76c3-4ce5-8d1a-f2cab319728c-S2","host":"10.134.52.126"}]}
Tasks field in response is an array. How to get first item from this array?
You can use 'jq' utility to parse json inputs.
In your case, it will be :
# To get First task details
cat response.json | jq '.tasks[0]'
# To get First task id
cat response.json | jq '.tasks[0].id'
# To get id of all tasks
cat response.json | jq '.tasks[] | .id'
Related
We have different type of logs for one and the same application. Some are coming from our application which logs in a JSON format and others are different types of log messages.
For example these 3 log lines:
"{\"written_at\": \"2022-03-30T07:51:04.934Z\", \"written_ts\": 1648626664934052000, \"msg\": \"Step 'X' started at 2022-03-30 07:51:04\", \"type\": \"log\", \"logger\": \"my-logger\", \"thread\": \"MainThread\", \"level\": \"DEBUG\", \"module\": \"my.module\", \"line_no\": 48}\n"
" ERROR Data processing error: Did not work \n"
"FileNotFoundError: [Errno 2] No such file or directory: '/local.json'\n"
To parse our application JSON logs we perform the following LogQL query:
| json log="log"
| line_format "{{.log}}"
| json | line_format "{{.msg}}"
| __error__ != "JSONParserErr"
As our query already states, we can not parse the other line logs since they are not in JSON format.
Can we define different parsing and formatting depending on conditions?
Or as fallback when the JSONParserErr happens?
I need to change the environment variable under container definition in the ecs Task Definition.
TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition $TASKDEFINITION_ARN --output json)
echo $TASK_DEFINITION | jq '.taskDefinition.containerDefinitions[0] | ( .environment[] |= if
.name == "ES_PORT_9200_TCP_ADDR" then .value = "vpc-kkslke-shared-3-abcdkalssdfy.us-east-1.es.amazonaws.com"
else . end)' | jq -s . >container-definition.json
CONTAINER_DEF=$(<$container-definition.json)
aws ecs register-task-definition --family $FAMILY_NAME --container-definitions $CONTAINER_DEF
Error Message:
Error parsing parameter '--container-definitions': Invalid JSON:
Expecting property name enclosed in double quotes: line 1 column 2
(char 1) JSON received: {
One observation not sure if it is related to a bug in VScode or not . When I try to use the view the variable value in debug mode. I only get partial text as seen below. But when I do echo for the same variable I do see the full json. Not sure if the whole value is being passed to the container definition.
I have been looking at the GitHub REST API and i have been trying to find out where I can find the endpoint to get the status of a workflow in my actions. The only way i can tell if it is passing or failing is by downloading the badge.svg.
You can use workflow run api :
GET https://api.github.com/repos/[owner]/[repo]/actions/workflows/[workflowID]/runs
[workflowID] can also be the filename, in the following example ci.yml :
https://api.github.com/repos/bertrandmartel/tableau-scraping/actions/workflows/ci.yml/runs
Then you can get the first run using curl and jq :
curl -s "https://api.github.com/repos/bertrandmartel/tableau-scraping/actions/workflows/ci.yml/runs" | \
jq -r '.workflow_runs[0].status'
output:
completed
I want to inspect a list of all routes, that Vapor app is serving. Is there a script or a run-time command that will generate the list for me?
I'm looking for something similar to rake routes in Ruby on Rails
Run vapor run routes from the command line after executing vapor build
Another alternative to get the routes use the following command. It will build your project and displays all routes registered to the Application's Router in an ASCII-formatted table.
$ swift run Run routes
+------+------------------+
| GET | /search |
+------+------------------+
| GET | /hash/:string |
+------+------------------+
A colon preceding a path component indicates a variable parameter. A colon with no text following is a parameter whose result will be discarded.
Is it possible to obtain last N number of commits to a particular branch in a GitHub repository using GitHub API ?
I just found few GitHub api details regarding the commits here, but none of them are giving details about last N number of commits!
Anyone can provide a better idea about this ?
Also, Is it possible to identify the changed file type during the last commit from a user ?
You can try this Github API to get the last N number of commits,
INPUT:
GIT_REPO="https://api.github.com/repos/kubernetes/kubernetes" # Input Git Repo
BRANCH_NAME="master" # Input Branch Name
COMMITS_NUM="5" # Input to get last "N" number of commits
curl --silent --insecure --request GET --header "Accept: application/vnd.github.inertia-preview+json" "$GIT_REPO/commits?sha=$BRANCH_NAME&page=1&per_page=1000" | jq --raw-output '.[] | "\(.sha)|\(.commit.author.date)|\(.commit.message)|\(.commit.author.name)|\(.commit.author.email)" | gsub("[\n\t]"; "")' | awk 'NF' | awk '{$1=$1;print}' | head -$COMMITS_NUM
OUTPUT:
COMMIT_ID|DATE/TIME|COMMIT_MESSAGE|AUTHOR_NAME|AUTHOR_EMAIL
5ed4b76a03b5eddc62939a1569b61532b4a06a72|2020-11-26T15:24:19Z|Merge pull request #96421 from dgrisonnet/fix-apiservice-availabilityFix aggregator_unavailable_apiservice gauge|Kubernetes Prow Robot|k8s-ci-robot#users.noreply.github.com
c1f36fa6f28d3618c03b65799bc3f58007624e5f|2020-11-25T06:32:41Z|Merge pull request #96829 from songjiaxun/azuredisk_api_versionfix: change disk client API version for Azure Stack|Kubernetes Prow Robot|k8s-ci-robot#users.noreply.github.com
c678434623be4957d892a9865e5649f887a40c49|2020-11-24T21:20:39Z|Merge pull request #96831 from bobbypage/vendor-cadvisor-v0_38_5vendor: update cAdvisor to v0.38.5|Kubernetes Prow Robot|k8s-ci-robot#users.noreply.github.com
c652ffbe4a29143623a1aaec39f745575f7e43ad|2020-11-24T14:59:01Z|Merge pull request #96636 from Nordix/disable-nodeport-2service.spec.AllocateLoadBalancerNodePorts followup|Kubernetes Prow Robot|k8s-ci-robot#users.noreply.github.com
4a46efb70701ee00028723ecb137e401d83be4f4|2020-11-24T07:45:19Z|vendor: update cAdvisor to v0.38.5|David Porter|david#porter.me
Note:
1.Make sure you have installed jq to get output in the desired format and parse json key as per your requirement.
2.Make sure to update the Git Repo Url in "curl" command.