Skip to content

Instantly share code, notes, and snippets.

@jarosite
jarosite / puppet_syntax_check.rb
Last active August 29, 2015 14:07
Hook for mercurial server. Will check syntax of puppet files, yaml files for hiera and erb template files. Add on serrver to .hg/hgrc [hooks] pretxnchangegroup = .hg/puppet_syntax_check.rb
#!/usr/bin/ruby
def chk(file_to_check, cmd)
puts "checking '#{file_to_check}'"
if !system("hg cat -r tip '#{file_to_check}' | #{cmd} 2>&1")
print('!!! Syntax error in file: ' + file_to_check + "\n")
exit(1)
end
end
@jarosite
jarosite / install_puppet.sh
Last active June 24, 2019 10:37
Install puppet on amazon linux, after ami lost back compatibility to centos 6.5
#!/bin/bash
yum install ruby18 rubygems18 -y
alternatives --set ruby /usr/bin/ruby1.8
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
yum install puppet-3.7.3 -y --disableplugin=priorities
@jarosite
jarosite / teamcity.rb
Last active August 29, 2015 14:07 — forked from agross/teamcity.rb
class TeamCity
def self.running?
ENV.include? 'TEAMCITY_PROJECT_NAME'
end
def self.method_missing(method, *args, &block)
return unless running?
message_name = camel_case method.to_s
publish message_name, args[0]
@jarosite
jarosite / clean_rev.bat
Created October 24, 2014 07:50
If you get 400 on pull from mercurial, while push is working, probably you have a lot of closed branches but not merged anywhere. Create trash branch, and run this script.
for /F %%x in ('hg log -r "heads(all()) and closed()" --template "{rev}"\n') do (call :merge "%%x")
GOTO :eof
:merge
hg --config ui.merge=internal:local -y merge --rev %1
hg commit -m merge
GOTO :eof
#!/bin/bash
set -x
set -e
REPO_NAME=production
YUM_SERVER_URL=http://localhost:8888/yum-repo-server
FILES=*.rpm
curl -s -d "name=$REPO_NAME" $YUM_SERVER_URL/repo
for f in $FILES
do
echo "Processing $f file..."
filter {
# Format Nginx Error logs
if [type] =~ /nginx_.*_error/ {
grok {
match => {
"message" => [
"%{DATESTAMP:timestamp} \[%{DATA:severity}\] (%{NUMBER:pid:int}#%{NUMBER}: \*%{NUMBER}|\*%{NUMBER}) %{GREEDYDATA:message}",
"%{DATESTAMP:timestamp} \[%{DATA:severity}\] %{GREEDYDATA:message}",
"%{DATESTAMP:timestamp} %{GREEDYDATA:message}"
]
@jarosite
jarosite / docker_clean_stopped_containers.sh
Last active August 29, 2015 14:22
remove stopped docker containers
docker rm $(docker ps -q -f status=exited)
@jarosite
jarosite / gist:61936e241e91738ba719
Last active August 29, 2015 14:27
Puppet external fact for EC2 Tags
#!/bin/bash
region=`facter ec2_placement_availability_zone | sed 's/[a-z]$//g'`
instanceId=`facter ec2_instance_id`
/usr/bin/aws ec2 describe-tags --filters "Name=resource-id,Values=${instanceId}" --region ${region} | jq '.Tags[] | "ec2_tag_" + .Key + "=" + .Value' | tr [:upper:] [:lower:] | tr -d '"'
exit 0
@jarosite
jarosite / ec2tags.rb
Last active August 29, 2015 14:27 — forked from rafaelfelix/ec2tags.rb
Hack to get ec2 tags to facter. Depends on aws-cli (https://github.com/aws/aws-cli), jq (http://stedolan.github.io/jq/) and the JSON RubyGem (http://rubygems.org/gems/json)
require 'facter'
require 'json'
if Facter.value("ec2_instance_id") != nil
instance_id = Facter.value("ec2_instance_id")
region = Facter.value("ec2_placement_availability_zone")[0..-2]
tags = Facter::Util::Resolution.exec("aws ec2 describe-tags --filters \"name=resource-id,values=#{instance_id}\" --region #{region} | jq '[.Tags[] | {key: .Key, value: .Value}]'")
parsed_tags = JSON.parse(tags)
parsed_tags.each do |tag|
@jarosite
jarosite / zabbix_sendemail
Created March 26, 2016 13:38
send email notification from zabbix using AWS SES
#!/bin/sh
set -e
set -x
#{
#date
export smtpemailfrom=support@blablabla.com
export zabbixemailto=$1
export zabbixsubject=$2
export zabbixbody=$3