Posts List

Simple script to selectively remove emails from postfix’s queue

Tweet If you send out a lot of emails, the queue in postfix might be full of junk emails from people putting like bla@example.net as their email address. Now there could be other valid emails in there that you don’t want to remove due to their mail server down and postfix keeps trying for a set amount of time to re-send that email. So below is a simple script that you have to run as root that you can enter a search string as a paramater to remove emails from the queue

Nagios check for monit

Tweet Here is a simple nagios check I just created to check the monitor status for monit. The background is as simple as this.. If you have a service that is flapping and monit is set to timeout after a number of failed attempts to start the service, it will un-monitor the service. Without m/monit running, you might never notice it is set as un-monitored. So I created a little python script to check for this

Mapping /proc/meminfo to output of free command

Tweet So an example output of free is total used free shared buffers cached Mem: <span style="color: #039b3d">12333980</span> 12151544 182436 0 <span style="color: #06e572">233128</span> <span style="color: #5656ff">11197680</span> -/+ buffers/cache: 720820 11613160 Swap: <span style="color: #005fbf">487416</span> 3536 <span style="color: #56aaff">483880</span> And /proc/meminfo <span style="color: #039b3d">MemTotal: 12333980 kB</span> MemFree: 182436 kB <span style="color: #06e572">Buffers: 233128 kB</span> <span style="color: #5656ff">Cached: 11197680 kB</span> SwapCached: 996 kB Active: 7296040 kB Inactive: 4231216 kB Active(anon): 73848 kB Inactive(anon): 22892 kB Active(file): 7222192 kB Inactive(file): 4208324 kB Unevictable: 0 kB Mlocked: 0 kB <span style="color: #005fbf">SwapTotal: 487416 kB</span> <span style="color: #56aaff">SwapFree: 483880 kB</span> Dirty: 268 kB Writeback: 0 kB AnonPages: 95640 kB Mapped: 7686976 kB Shmem: 292 kB Slab: 346296 kB SReclaimable: 335352 kB SUnreclaim: 10944 kB KernelStack: 1920 kB PageTables: 23844 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 6654404 kB Committed_AS: 613716 kB VmallocTotal: 34359738367 kB VmallocUsed: 309052 kB VmallocChunk: 34359422748 kB HardwareCorrupted: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 10240 kB DirectMap2M: 12572672 kB I’ve done my best to match up the two outputs via colors.

Varnish ACL with X-Forwarded-For Header

Tweet So I did a setup like this once nginx -> varnish -> backend apaches I did the nginx in front of varnish to handle SSL termination since varnish doesn’t do SSL. So the issue is you can do this for subnet checking in your varnish config acl vpn { "192.168.0.0"/16; } sub vcl_recv { if (client.ip ~ vpn) { # something here } return(pass); } So the issue with this is varnish thinks the client.

Postfix ignore catchall relayhost

Tweet Postfix has an option where you can setup a relayhost to send all mail to another mail server. It looks something like relayhost = [mail.domain.com]:25 So that will send all mail being sent out from the server to mail.domain.com on port 25. So what happens if you want to send mail that is sent to company.com out that server and not through another relay. You would do the following in main.

ps aux with line wrap

Tweet File this under you learn something new every day. Ever do a ps aux only to get something like this to happen? xymon 26931 0.0 0.0 38944 1396 ? S 05:44 0:00 sh -c vmstat 300 2 1>/usr/lib64/xymon/client/tmp/hob So the output of ps aux gets cut off when it hits the end of your terminal. And you have to expand your width a lot to see it. It always bothered me till I decided to read the man page.

Fabric Shell

Tweet I recently wrote a quick little fabric function to create a fabric shell. This works with a stock fabric install, you just might have to change where you import it from. It is at my Github page below. https://github.com/mzupan/fabric_shell If you place shell.py in the same directory as fabfile.py you can use it like from fabric.api import * from fabric.decorators import hosts import shell env.hosts = [ 'host1.domain.com', 'host2.

Fun with Django ManyToMany Fields

Tweet This is just another reason I find Django so easy. For example.. Say you are making a monitoring application. Now you have a bunch of servers and you have certain groups of servers. A server can belong in more then one group also. So that is pretty easy and all with Django. Now in your template you have a few pages. One page that displays the group information like all the servers in the group and another that displays the server information and will list all the groups that server is in.

Crontab with a random sleep

Tweet Recently ran into this problem. We had a crontab entry that looked something like this 0 0 * * * /usr/bin/sleep $((RANDOM\%90)); cmdHere What that attempted was to run a command a random amount of seconds once midnight hit. Now running the command on console causes it to error out $ /usr/bin/sleep $((RANDOM\%90)) -bash: RANDOM\%90: syntax error: invalid arithmetic operator (error token is "\%90") So what you might be saying is well the \ is messing it up so remove it.

Atomic Symlink Changes

Tweet A common deploy strategy for a lot of web sites is as follows v1.0.10 v1.0.11 v1.1.0 current -> v1.1.0 So in this directory we have three directories and one symlink. The directories contain our web application and are tagged with the source control version they were tagged with by the developers. Now its a common practice when deploying a new version to upload the new release which will be v1.