Skip to content

Instantly share code, notes, and snippets.

@bfleming-ciena
bfleming-ciena / gist:06ab3531a1c30c3b998a
Created February 18, 2015 20:06
Simple example using python scp module to do wildcard scp with progress
from paramiko import SSHClient
from scp import SCPClient
def progress(filename, size, sent):
print filename + " " + str(size) + " " + str(sent)
if __name__ == "__main__":
ssh = SSHClient()
ssh.load_system_host_keys()
@bfleming-ciena
bfleming-ciena / dumpaz.sh
Created February 7, 2020 03:53
Dump all azure resources
# Dumps all resources in all subscriptions and pulls fields related to the resource and most
# importantly, the tags currently applied.
#
# I was using this to import into an excel spreadsheet, which we then reviewed and modified the tag values.
# Then I would dump the spreadsheet back to csv and feed it into the python script which would go and
# update the tags.
echo "id,location,it_Environment,it_App,it_Role,it_Owner,name,resource group,kind,type,tags"
for i in $(az account list -o tsv|cut -f2); do
az resource list --subscription="$i" | jq -r '.[] | [.id,.location,"","","","",.name,.resourceGroup,.kind,.type,(.tags | tostring)] | @csv'
done
2019-04-18T18:00:09.690 [Information] Executing 'Functions.azure-auto-tag-creator' (Reason='This function was programmatically called via the host APIs.', Id=b265df84-a1cf-4fb2-b8bb-611c0d54b721)
2019-04-18T18:00:09.806 [Error] Executed 'Functions.azure-auto-tag-creator' (Failed, Id=b265df84-a1cf-4fb2-b8bb-611c0d54b721)
Result: Failure
Exception: ValueError: time data '9999-12-31T23:59:59.9999999+00:00' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'
Stack: File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/dispatcher.py", line 273, in _handle__invocation_request
pytype=pb_type_info.pytype)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/bindings/meta.py", line 296, in from_incoming_proto
trigger_metadata=trigger_metadata)
File "/root/.pyenv/versions/3.6.8/lib/python3.6/site-packages/azure/functions_worker/bindings/queue.py", line 89, in from_proto
trigger_metadata, 'ExpirationTime'),
@bfleming-ciena
bfleming-ciena / gist:1513f7b9f379aa8c9da3f9677bf490b9
Created January 29, 2019 18:27
debug output for possible bug with boot_diagnostics enabling
~ module.vms_dmz_sqldmz.module.SQLDMZ1.azurerm_virtual_machine.vm-windows-with-datadisk
boot_diagnostics.0.enabled: "false" => "true"
boot_diagnostics.0.storage_uri: "https://clustwitsqldmzdr77aa.blob.core.windows.net" => "https://clustwitsqldmzdr77aa.blob.core.windows.net/"
Running appy repeatedly finds the same change.
@bfleming-ciena
bfleming-ciena / gist:c1d3e5a5b77a156473a8
Last active September 8, 2018 18:59
Pull estimated AWS charges Billing
#list metrics
aws --profile dev --region us-east-1 cloudwatch list-metrics --namespace "AWS/Billing"
# Estimated charges
aws --region us-east-1 cloudwatch get-metric-statistics --namespace "AWS/Billing" --metric-name "EstimatedCharges" --dimension "Name=Currency,Value=USD" --start-time $(gdate +"%Y-%m-%dT%H:%M:00" --date="-12 hours") --end-time $(gdate +"%Y-%m-%dT%H:%M:00") --statistic Maximum --period 60 --output text | sort -r -k 3 | head -n 1 | cut -f 2
# Marketplace Charges
aws --profile dev --region us-east-1 cloudwatch get-metric-statistics --namespace "AWS/Billing" --metric-name "EstimatedCharges" --dimensions Name=ServiceName,Value=AWSMarketplace Name=Currency,Value=USD --start-time $(gdate +"%Y-%m-%dT%H:%M:00" --date="-12 hours") --end-time $(gdate +"%Y-%m-%dT%H:%M:00") --statistic Maximum --period 60 --output text
# Redshift
@bfleming-ciena
bfleming-ciena / gist:fd168f7475af46bbd5ff6fe9aa93215e
Created July 17, 2018 21:09
Looking through a list of maps
count = length(list)
lookup(list[count.index], "subscription_id")
@bfleming-ciena
bfleming-ciena / gist:492075edcfc3e51874f3a66f7e49ed33
Last active June 5, 2018 22:56
Rancher 1.6.13, Kubernetes 1.9.5, Istio .0.8.0 Configuration (working)
Deployment
Update kube-apiserver (it is under the service kubernetes) in rancher via the UI.
click upgrade
Replace the command line with this. The IP range is my cluster IP range, yours could be different, just use what was there for you.
kube-apiserver --storage-backend=etcd2 --storage-media-type=application/json --service-cluster-ip-range=10.43.0.0/16 --etcd-servers=http://etcd.kubernetes.rancher.internal:2379 --insecure-bind-address=0.0.0.0 --insecure-port=0 --cloud-provider=rancher --allow_privileged=true --admission-control=NamespaceLifecycle,LimitRanger,ServiceAccount,PersistentVolumeLabel,DefaultStorageClass,DefaultTolerationSeconds,ResourceQuota,MutatingAdmissionWebhook,ValidatingAdmissionWebhook --client-ca-file=/etc/kubernetes/ssl/ca.pem --tls-cert-file=/etc/kubernetes/ssl/cert.pem --tls-private-key-file=/etc/kubernetes/ssl/key.pem --kubelet-client-certificate=/etc/kubernetes/ssl/cert.pem --kubelet-client-key=/etc/kubernetes/ssl/key.pem --runtime-config=batch/v2alpha1 --anonymous-auth=false --a
@bfleming-ciena
bfleming-ciena / gist:337fb43582cc02694ab1ff7e5db42689
Created June 5, 2018 04:44
kubernetes cluster and namespace bash prompt (tested with os-x)
# Sorry for not mentioning the credit to the original author. I lost the original link. I just added the namespace to the picture.
function kube_context() {
# could have used $?, but it was easier with a string compare
local ctx=$(kubectl config current-context 2>&1)
local ns=$(kubectl config get-contexts --no-headers | grep '*' | awk '{print $5}')
if [ "${ctx}" != "error: current-context is not set" ]; then
echo -n "<${ctx}:$ns> "
fi
}
@bfleming-ciena
bfleming-ciena / gist:018882175ffa8efb57a7d594385cd6c7
Last active March 19, 2018 19:50
K8s Prometheus CoreOS Operator - Adding external nodes to be monitored.
-- My need was to include nodes outside of my k8s cluster for monitoring.
-- Thanks to @amalucelli for originally posting this.
-- https://github.com/coreos/prometheus-operator/issues/834
--
-- This is tested with k8s 1.9, and .17 prometheus operator, using the pre-built deployment at
-- https://github.com/coreos/prometheus-operator/blob/master/contrib/kube-prometheus/README.md
-- Steps: Deploy per the script above, and then apply these objects. Should appear in granfa after a short time.
kind: Service
apiVersion: v1
gitfs_remotes:
- http://ourrepo/repos/sxa/repo.git:
- saltenv:
- csdev:
- ref: salt-csdev
- root: 'salt/env'