Tuesday, July 15, 2014
Receiving SQS messages through SNS - Decoding the payload
http://www.elastician.com/2010/04/subscribing-sqs-queue-to-sns-topic.html
User Chris Moyer points out:
One very important thing to note here is that the messages from SNS do NOT come through as base64 encoded, so you'll have to set the message class to "RawMessage" first:
from boto.sqs.message import RawMessage
q.set_message_class(RawMessage)
msg = q.read()
Also, the message "payload" is actually stored under "Message" in the provided JSON:
msg_data = json.loads(msg.get_body())['Message']
Sunday, December 1, 2013
Fixing an Off-Screen DiffMerge window in OS X
Best way is to rm the plist file in ~/Library/Preferences and remove the window dimensions in the file literally named: "~/Library/Preferences/Sourcegear Diffmerge Preferences"
Wednesday, November 20, 2013
Quick rsyslog setup
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
Add "- 4" to /etc/sysconfig/rsyslog to get it to listen on IPv4 addresses. Example:
SYSLOGD_OPTIONS="-c 5 -4"
Restart the service
On the Client:
*.* @@remote-host:514
On EC2 instance boot, pass this to user-data:
#!/bin/bash
echo '*.* @@host_name_or_ip:514' >> /etc/rsyslog.conf
/etc/init.d/rsyslog restart
Tuesday, November 27, 2012
Puppet & Mcollective
How-To: Install Mcollective & Puppet on EC2
by nathanmc@
=======
EC2 Prep
Create security groups with the following rules:
jump - tcp/22 - 0.0.0.0/0 puppet-cli mcoll-cli rabbit mcoll-queue - tcp/6163 - mcoll-cli puppet-master - tcp/8140 - puppet-cliSet Up RabbitMQ
Instantiate a 64-bit m1.large of Ubuntu 12.04 LTS
Security Groups: * rabbit * mcoll-queue * puppet-master * jump- SSH to the rabbitmq host and
sudo su - Execute:
apt-get install -y erlang-base erlang-nox wget http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.1/rabbitmq-server_2.8.1-1_all.deb dpkg -i rabbitmq-server_2.8.1-1_all.deb rabbitmq-plugins enable amqp_client rabbitmq-plugins enable rabbitmq_stompEdit /etc/rabbitmq/rabbitmq.config:
[ {rabbitmq_stomp, [{tcp_listeners, [{"0.0.0.0", 6163}, {"::1", 6163}]}]} ].Execute:
rabbitmqctl add_user mcollective PASSWORD rabbitmqctl set_user_tags mcollective administrator rabbitmqctl set_permissions -p / mcollective ".*" ".*" ".*" /etc/init.d/rabbitmq-server restartSanity check - Ensure it's now listening on 6163:
netstat -anp | grep -v unix ... tcp 0 0 0.0.0.0:6163 0.0.0.0:* LISTEN 1240/beam tcp6 0 0 ::1:6163 :::* LISTEN 1240/beamIf you don't, check your history to ensure you enabled the rabbitmq_stomp plugin
Also look at /var/log/rabbitmq/startup*_log files for clues as to why it may not have started
Leave your terminal open and run
tail -f /var/log/rabbitmq/rabbit@*hostname*.logThis will show you the connections as they come in from the clients
Set Up Mcollective
Instantiate a 64-bit client host of either Ubuntu 12.04 LTS or Amazon Linux AMI 2012.03
Security Groups: * jump * puppet-cli * mcoll-cliSSH in and apply all updates
Amazon: sudo su - yum update shutdown -r now Ubuntu sudo su - apt-get update apt-get upgrade shutdown -r nowSSH in and execute:
Amazon: sudo su - edit /etc/yum.repos.d/epel.repo set all to enabled=0 yum install rubygem-stomp rpm -ivh http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-5.noarch.rpm yum install mcollective mcollective-clientMake the following edits:
/etc/hosts - add the line: <internal ip of your rabbit host> puppet /etc/mcollective/server.cfg: plugin.psk = 01234 (NOTE: Pre-Shared Key - Can be any value consistent across all) plugin.stomp.host = puppet plugin.stomp.port = 6163 plugin.stomp.user = mcollective plugin.stomp.password = PASSWORD /etc/mcollective/client.cfg: plugin.psk = 01234 (NOTE: Pre-Shared Key - Can be any value consistent across all) plugin.stomp.host = puppet plugin.stomp.port = 6163 plugin.stomp.user = mcollective plugin.stomp.password = PASSWORDRestart mcollective
/etc/init.d/mcollective startTest mcollective via the following command:
mco find hostsShould see your localhost's name
If not, double-check that all the passwords and psk's are the name in client and server cfg's
Logs are written to /var/log/mcollective.log
You should see connections listed in the log on rabbitmq
Setup Puppet
NOTE: This guide works for puppet 2.6.x CLIENTS. Be careful about what version you're installing because most repos have more than one.
Back on the rabbitmq server, execute:
apt-cache policy puppetmasterYou should see output similar to the following
puppetmaster: Installed: (none) Candidate: 2.7.11-1ubuntu2.1 Version table: 2.7.11-1ubuntu2.1 0 500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ precise-updates/main amd64 Packages 500 http://security.ubuntu.com/ubuntu/ precise-security/main amd64 Packages 2.7.11-1ubuntu2 0 500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ precise/main amd64 PackagesFor our purposes, a 2.7 server will work fine, so install it with:
apt-get install puppetmaster cd /etc/puppet mkdir files cd manifestsEdit site.pp
#/etc/puppet/manifests/site.pp import "nodes" filebucket { main: server => "<resolvable host name of self>" } #defaults File { backup => main } Exec { path => "/usr/bin:/usr/sbin:/bin:/sbin" }Edit nodes.pp
# /etc/puppet/manifests/nodes.pp # We're just going to put a simple example node default { exec { "touch_file": command => "touch /tmp/stamped.txt", path => "/usr/local/bin/:/bin/", } }Edit /etc/puppet/autosign.conf (just an asterisk)
*Restart the puppet daemon:
/etc/init.d/puppetmaster restartOn each puppet client:
Amazon Linux:
yum info puppet ... Available Packages Name : puppet Arch : x86_64 Version : 2.6.16 Release : 1.6.amzn1 Size : 843 k Repo : amzn-updates Summary : A network tool for managing many disparate systems URL : http://puppetlabs.com License : GPLv2 yum -y install puppet wget https://s3.amazonaws.com/trnsfr/nsmc-mco-puppetd-1.0.0-1.x86_64.rpm rpm -ivh nsmc-mco-puppetd-1.0.0-1.x86_64.rpm wget https://s3.amazonaws.com/trnsfr/nsmc-mco-facter-facts-1.0.0-1.x86_64.rpm rpm -ivh nsmc-mco-facter-facts-1.0.0-1.x86_64.rpmEdit the mcollective configs:
/etc/mcollective/client.cfg: # Facts factsource = facter /etc/mcollective/server.cfg: # Facts factsource = facterRestart mcollective:
/etc/init.d/mcollective restart
Monday, May 30, 2011
Symfony Deployment Gotcha
Namely, Symfony creates a rather expansive directory structure that - for security reasons - can't all live under your web root. The solution all the tutorials have you do is to set up the actual project in your home directory and then create an Apache virtual server that points to it. Seems simple enough. And you can add it to your config without any griping from Apache. Symfony has all the global perms set, so you're good, right?
Wrong, unfortunately. I was getting "403 Forbidden" over and over. I tried a wide variety of fixes, none of which worked. Eventually, I found this post on google groups:
http://bit.ly/mNRrlV
Sure enough, I checked the root perms of my home directory and it was all tightened down:
drwx------ 17 user user 4096 May 30 06:16 user
Just goes to show you the danger of returning to "childlike innocence" with new projects.
In reality, the right way to approach this is to create a project-specific directory somewhere under /usr/local and consciously set perms for the whole thing.
Following that approach, you get the right results straight out of the gate:
[root@localhost local]# ls -ld projects/
drwxr-xr-x 3 root root 4096 May 30 07:17 projects/
[root@localhost local]# ls -ld projects/milkshake/
drwxr-xr-x 11 root root 4096 May 30 07:18 projects/milkshake/
Now, you create your Symfony project under that:
symfony generate:project --orm=Propel milkshake
And your app:
symfony generate:app frontend
Finally, you add the following to your httpd.conf:
# Be sure to only have this line once in your configuration
NameVirtualHost *:8080
# This is the configuration for your project
Listen *:8080
<VirtualHost *:8080>
DocumentRoot "/usr/local/projects/milkshake/web"
DirectoryIndex index.php
<Directory "/usr/local/projects/milkshake/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
This is a good lesson for everybody: please check what you write and all your other assumptions, as well.
Friday, February 25, 2011
swatch queues messages
Friday, January 28, 2011
Make your own daemon
#!/bin/sh # Simple Log Watcher Program case "$1" in 'start') /usr/bin/swatch --daemon --config-file=/etc/swatch.conf --tail-file=/var/log/auth.log --pid-file=/var/run/swatch.pid ;; 'stop') PID=`cat /var/run/swatch.pid` kill $PID ;; *) echo "Usage: $0 { start | stop } ;; esac exit 0 Thursday, January 27, 2011
Unattended Ubuntu Apt Installs
When you want to
apt-get install package
and you don't want to get prompted for values, etc, just add the following the front of your shell:
export DEBIAN_FRONTEND=noninteractive
Poof. Magic.
Sunday, January 2, 2011
Grepping out comments and blank lines
- Read the contents of file
- Remove all lines with "#"
- Pass the result to egrep
- Egrep: remove all lines which begin and immediately end (ie, a blank line) and output the result
Monday, October 25, 2010
Subversion Set Up
Thursday, September 2, 2010
File Encryption with OpenSSL
My personal favorite (since it can be used in any situation) is the openssl file encryption capability. The openssl package is almost universally installed by default in distros these days, so you should just be able to jump straight to the commands.
In this case, I've got a file called "spreadsheet.xls" that I want to password encrypt. The syntax is simply this:
openssl aes-256-cbc -a -salt -in spreadsheet.xls -out spreadsheet.xls.enc
Then just supply the password you want to use.
And when you want to decrypt it, just add the '-d' switch and flip the filenames:
openssl aes-256-cbc -d -a -in spreadsheet.xls.enc -out spreadsheet.xls
And use your password.
Just like that, you've got munition-grade encryption from the command-line.
Enjoy
Saturday, August 14, 2010
Zenoss Quirks
1. It was marking my apache process monitor as failed/recovered randomly and often.
2. It would not let go of misapplied process monitors that had been picked-up by overly liberal regexes. It would include:
tail -f /var/log/nginx/access.log
nginx: worker
in the nginx process monitor if I was tailing the log when I modeled the host. The problem was, after I killed the tail, the process was alerting as "Process Not Running". FOREVER. Even if I deleted and recreated the process monitor, the host, the events, everything.
In the first case, it turns out that since apache marks its process as "apache defunct
apache2 \-k start
The second case was much more obnoxious because not only would the events not clear, they would return and begin alerting every time the device was recreated.
After some digging online, it seemed that the best course was to restart the zenprocess daemon.
This is best done under Settings > Daemons. You can also view the logs there (which showed the bad checks prior to the restart and nothing after).
When that's complete, re-add your device and you should be rid of the baggage.
Wednesday, July 28, 2010
Tethering your iPhone in Ubuntu
sudo add-apt-repository ppa:pmcenery/ppa
sudo apt-get update
Now install the following three packages (you may have to go dig for them):libimobiledevice-utils
ipheth-dkms
ipheth-utils
Restart your machine.
Turn on tethering inside your iPhone's General > Network menu.
Cable your iPhone to a USB port.
It should automatically connect. You'll see it in Network Manager.
Poof. Magic.
Sunday, July 25, 2010
Enabling SSH Agent Forwarding in OS X
Thursday, July 8, 2010
Removing packages from Debian/Ubuntu
A coworker of mine forced a package install without repositories so all the dependencies obviously failed. Trying to remove it, I did a
dpkg --remove
But running an apt-get said it was still installed. Running
dpkg --list
Gave me a status of "rc" - which left a lot of files laying around. (Configs, etc.)
Finally, I just did a
dpkg --purge
And it cleared out all the junk.
From there, I was able to do a normal apt-get against the repositories.
Wednesday, June 30, 2010
Using Exim as a Mail Relay
This is all well and good, but there are a few inevitable problems one is likely to run into when putting one up.
By far, I've had the most success with Exim running on Debian since both are very lightweight, incredibly reliable and closely intertwined. (Exim is Debian's default MTA.)
Step 1 is to provide the basic setup. Log in, su to root and run the following:
dpkg-reconfigure exim4-config
When that's complete, you need to cd into /etc/exim4 and modify the exim4.conf.template file. Find the rewrite section by looking for
begin rewrite
Then add your rewrite rule under it. This will make it apply to all messages that pass thorugh Exim.
The generic rule I usually use looks like this:
*@* $1@
What it essentially says is "match everthing (*@*) and replace what's in front of the @ with what was to the left of the original and everything after the @ with with explicit domain name - also, apply it to the following types of addresses: F - envelope From field, f - From header, r - Reply-To header, s - Sender header"
With that rule in place, restart Exim:
invoke-rc.d exim4 restart
And the config will be written out to /var/lib/exim4/configuration.autogenerated.
The best way to test is to use the Exim command line to see what rewrites will get applied:
# exim -brw root@localhost
sender: root@
to: root@localhost
cc: root@localhost
bcc: root@localhost
reply-to: root@
env-from: root@
env-to: root@localhost
With that done, you need to take care of the blacklists. First, add an A record to your domain's authoritative DNS WITH A PTR. The reverse lookup is used as a method to ensure the mail server is a legitimate member of your domain. NOTE: A lot of people think MX records are required but that's incorrect. MX records are for inbound mail only.
Now fire off some messages to big mail destinations like gmail and yahoo. Tail the /var/log/exim4/mainlog to see what results you get. Yahoo especially is good about telling you where your IP is blacklisted for some reason. If it is, you'll get a lot of dropped messages till you contact the Blacklister and petition to have it removed.
On that same note, be careful about sending out a bunch of unsoliticed test messages. I've seen hosts get black-listed for that reason alone and it's a pain to get delisted.
Friday, May 21, 2010
Checking for Root
The easiest way to resolve that is to simply use the EUID bash variable to check the effective user-id you're executing under and then exit if it's not zero.
I cribbed the following
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
From this excellent article:
http://www.cyberciti.biz/tips/shell-root-user-check-script.html
Thursday, May 20, 2010
Awk Alternative Delimiters
For instance, if you wanted the ip of eth0, you could run
/sbin/ifconfig eth0
And you'd get back something like
[nsmc@nsmc-dt automation]$ /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:26:F2:AC:C2:FE
inet addr:10.1.1.99 Bcast:10.1.3.255 Mask:255.255.252.0
inet6 addr: fe80::226:f2ff:feac:c2fe/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1142141 errors:0 dropped:0 overruns:0 frame:0
TX packets:223927 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:212209959 (202.3 MiB) TX bytes:205106885 (195.6 MiB)
Interrupt:18 Base address:0x2000
Then you could vi into your config script and export the value to a var manually.
-OR-
You could set the variable with the returned value of a system command after clearing away some noise.
Using an iterative approach, we could peel back each layer till we get the piece we want:
/sbin/ifconfig eth0 | grep "inet "
That gives us the "inet" line and not the "inet6" line.
[nsmc@nsmc-dt automation]$ /sbin/ifconfig eth0 | grep "inet "
inet addr:10.1.1.99 Bcast:10.1.3.255 Mask:255.255.252.0
But we only want the piece behind the first colon. Here we need to use a little awk trickery. awk uses spaces for it's default field delimiters. Let's change that to a colon (:) and see what we get.
[nsmc@nsmc-dt automation]$ /sbin/ifconfig eth0 \
| grep "inet " | awk -F \: '{print $2}'
10.1.1.99 Bcast
Close. Now we can pass it through a standard awk filter and just get the piece we want:
[nsmc@nsmc-dt automation]$ /sbin/ifconfig eth0 | grep "inet " \
| awk -F \: '{print $2}' | awk '{print $1}'
10.1.1.99
Now we just need to assign to our variable at runtime using the backtic's:
export PRIVATE_HOST_IP=`/sbin/ifconfig eth0 | grep "inet " \
| awk -F \: '{print $2}' | awk '{print $1}'`
Tuesday, April 27, 2010
Escaping Single-Quotes in sed
Using single quotes in BASH ensures that the shell doesn’t expand the contents of the quoted string and this is useful most of the time. However if you want to use single quotes within a single quoted string things don’t work out as you might expect.
If I want to use sed to match some text with a single quotes in it, I will run into trouble if I run:sed 's/user \= 'root/user \= 'moi/g'
sed 's/user \= \'root/user \= \'moi/g'
I will get:
/bin/bash: -c: line 1: unexpected EOF while looking for matching `''
/bin/bash: -c: line 2: syntax error: unexpected end of file
This doesn’t work because the escaped single-quotes (\') are not expanded and are therefore treated literally.
To single quotes work you need to break out of the single quoted string then escape your single quote. Like so:
sed 's/user \= '\''root/user \= '\''moi/g'
Because \' is not inside of single quotes the single-quote is properly escaped and the output is as we’d expect:
user = 'root' -> user = 'moi' In conclusion, the title of this post is a bit of a misnomer. You actually can’t put single quotes inside of a single-quoted string. However breaking out allows us to get to where we want to be.
Sunday, April 18, 2010
Installing Amazon EC2 tools to Debian Lenny
First, install the Sun JDK (see my previous post on how to do that).
With that done, download the tools from this page:
AWS Developer Community
Or simply by using this link:
ec2-api-tools.zip
Next, unzip them.
Then create a configuration file to export the proper environment variables when your shell fires up:
$ vi ~/.ec2.conf
Add the lines:
export EC2_CERT=
export EC2_PRIVATE_KEY=
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export EC2_HOME=whereveryourec2toolswererunzipped
Save it.
Now add this to the bottom of your .bashrc:
. ~/.ec2.conf
Start a new shell and test for the var's using:
$ export | grep EC2
if they're there, you're all set.
Now test by cd'ing into your ec2 tools bin folder and running:
ec2-describe-images -o self -o amazon
If you get a huge java stack trace, changes are your jdk isn't installed properly.
Otherwise, you should get a very long list of all the amazon AMI's available to run from.