Skip to content

Instantly share code, notes, and snippets.

@pkazi
pkazi / dcosAppsReport.sh
Last active June 23, 2018 17:27
DCOS Apps Report
#!/bin/bash
TMP_CSV_FILE=$(mktemp /tmp/dcos-config.XXXXXX.csv)
TMP_CSV_FILE_SORT="${TMP_CSV_FILE}_sort"
#dcos marathon app list --json | jq '.[] | if (.container.docker.image != null ) then .id + ",Docker Application," + .container.docker.image else .id + ",DCOS Service," + .labels.DCOS_PACKAGE_VERSION end' -r > $TMP_CSV_FILE
dcos marathon app list --json | jq '.[] | .id + if (.container.type == "DOCKER") then ",Docker Container," + .container.docker.image else ",Mesos Container," + if(.labels.DCOS_PACKAGE_VERSION !=null) then .labels.DCOS_PACKAGE_NAME+":"+.labels.DCOS_PACKAGE_VERSION else "[ CMD ]" end end' -r > $TMP_CSV_FILE
sed -i "s|^/||g" $TMP_CSV_FILE
sort -t "," -k2,2 -k3,3 -k1,1 $TMP_CSV_FILE > ${TMP_CSV_FILE_SORT}
cnt=1
printf '%.0s=' {1..150}
@pkazi
pkazi / getDcosNodes.sh
Last active June 23, 2018 17:27
Get DCOS nodes with node attributes, number of tasks running, memory and cpu available
#!/bin/bash
printf "\n %-15s %-18s%-18s%-10s%-15s%-10s\n" "Node Type" "Node IP" "Attribute" "Tasks" "Mem Free (MB)" "CPU Free"
printf '%.0s=' {1..90}
printf "\n"
TAB=`echo -e "\t"`
dcos node --json | jq '.[] | if (.type | contains("leader")) then "Master (leader)" elif ((.type | contains("agent")) and .attributes.public_ip != null) then "Public Agent" elif ((.type | contains("agent")) and .attributes.public_ip == null) then "Private Agent" else empty end + "\t"+ if(.type |contains("master")) then .ip else .hostname end + "\t" + (if (.attributes | length !=0) then (.attributes | to_entries[] | join(" = ")) else "NA" end) + "\t" + if(.type |contains("agent")) then (.TASK_RUNNING|tostring) + "\t" + ((.resources.mem - .used_resources.mem)| tostring) + "\t\t" + ((.resources.cpus - .used_resources.cpus)| tostring) else "\t\tNA\tNA\t\tNA" end' -r | sort -t"$TAB" -k1,1d -k3,3d -k2,2d
printf '%.0s=' {1..90}
printf "\n"
@pkazi
pkazi / addDcosNodeAttributes.sh
Created June 23, 2018 08:05
Add node attributes to dcos nodes and run apps on nodes with required attributes using placement constraints.
#!/bin/bash
#1. SSH on node
#2. Create or edit file /var/lib/dcos/mesos-slave-common
#3. Add contents as :
# MESOS_ATTRIBUTES=<key>:<value>
# Example:
# MESOS_ATTRIBUTES=TYPE:DB;DB_TYPE:MONGO;
#4. Stop dcos-mesos-slave service
# systemctl stop dcos-mesos-slave
#!/bin/bash
# Usage : bash installDCOSDataDogMetricsPlugin.sh <Datadog API KEY>
DDAPI=$1
if [[ -z $DDAPI ]]; then
echo "[Datadog Plugin] Need datadog API key as parameter."
echo "[Datadog Plugin] Usage : bash installDCOSDataDogMetricsPlugin.sh <Datadog API KEY>."
fi
@pkazi
pkazi / dcosTaskExec.sh
Last active June 27, 2018 06:20
Execute commands in any dcos task. dcos task exec cli is only for mesos containers, this script can be used to ssh into mesos and docker containers.
#!/bin/bash
echo "DCOS Task Exec 2.0"
if [ "$#" -eq 0 ]; then
echo "Need task name or id as input. Exiting."
exit 1
fi
taskName=$1
taskCmd=${2:-bash}
TMP_TASKLIST_JSON=/tmp/dcostasklist.json
@pkazi
pkazi / cloudTrailEventNames.list
Last active March 23, 2024 09:37
List of values for parameter EventName in AWS Cloudtrail events
AbortDocumentVersionUpload
AbortEnvironmentUpdate
AbortMultipartUpload
AbortVaultLock
AcceptAccountMapping
AcceptCertificateTransfer
AcceptDelegate
AcceptDirectConnectGatewayAssociationProposal
AcceptFxPaymentCurrencyTermsAndConditions
AcceptHandshake
@pkazi
pkazi / setupLocalRedisCluster.sh
Created October 16, 2018 06:50
Setup Local redis cluster with 6 nodes (3 master and 3 slaves)
#!/bin/bash
CLUSTER_HOME=$HOME/redis-cluster
echo "Cluster Home is set to : $CLUSTER_HOME"
rm -rf $CLUSTER_HOME
mkdir -p $CLUSTER_HOME
cd $CLUSTER_HOME
wget http://download.redis.io/redis-stable/src/redis-trib.rb
chmod +x redis-trib.rb
mkdir 7000 7001 7002 7003 7004 7005
@pkazi
pkazi / dcosGetPublicIP.sh
Created October 22, 2018 09:06
DCOS Get Public IP of all Public Nodes
#!/bin/bash
for id in $(dcos node --json | jq --raw-output '.[] | select(.attributes.public_ip == "true") | .id');
do
dcos node ssh --option StrictHostKeyChecking=no --option LogLevel=quiet --master-proxy --mesos-id=$id "curl -s ifconfig.co"
done 2>/dev/null
@pkazi
pkazi / dcosAddUsers.sh
Created October 22, 2018 09:08
DCOS add users to Organization using CLI ( Open Source DCOS)
#!/bin/bash
# Uage dcosAddUsers.sh <Users to add are given in list.txt, each user on new line>
for i in `cat users.list`;
do
echo $i
curl -X PUT -H "Authorization: Bearer $(dcos config show core.dcos_acs_token)" "$(dcos config show core.dcos_url)/acs/api/v1/users/$i" -d "{}"
done
@pkazi
pkazi / dcosDeleteUsers.sh
Created October 22, 2018 09:10
DCOS delete users from organization using CLI (Open Source DCOS)
#!/bin/bash
# Usage dcosDeleteUsers.sh <Users to delete are given in list.txt, each user on new line>
for i in `cat users.list`;
do
echo $i
curl -X DELETE -H "Authorization: Bearer $(dcos config show core.dcos_acs_token)" "$(dcos config show core.dcos_url)/acs/api/v1/users/$i" -d "{}"
done