Monday, 16 April 2012

USB serial on mac os x

Generally you'll be using the same chipset all over - the PL2303
TO get this wokring, you'll need to download the driver from here:

http://sourceforge.net/projects/osx-pl2303/

Then you need the hyperterminal equivalent on Mac OS X, and you can actually run this in screen

If the driver is installed correctly you should have it displayed in dev

ls /dev/tty.*

and get something like this::
$ ls -al tty.*
crw-rw-rw- 1 root wheel 18, 4 Jan 25 07:32 tty.Bluetooth-Modem
crw-rw-rw- 1 root wheel 18, 8 Jan 25 07:32 tty.Bluetooth-PDA-Sync
crw-rw-rw- 1 root wheel 18, 10 Jan 25 09:20 tty.PL2303-0000103D
crw-rw-rw- 1 root wheel 18, 0 Jan 25 07:32 tty.SerialPort-1


then to set the speed you connect:

screen /dev/tty.PL2303-0000103D 9600

Easy Peasy!

Ctrl+A then control , to quit screen

 

Wednesday, 11 April 2012

Getting Mac OS X to use google apps as a mail proxy

First of all, I have a macbook air which mails me everytime it wakes up, it's status and it's current IP.

I had this originally use my firewall at home as a mail proxy, but obviously, when am *not* at home, this doesn't work.

So what I configured is how to use google's mail server to act as my SMTP server over SSL - great huh?

I would suggest you setup a sub domain e.g. sub.domain.com so that it was it's own set of credentials and security, and doesn't use your main account (which will have admi rights for the entire domain) e.g. I own bobcats.org, and the address phil@bobcats.org, so I'll setup root@sub.bobcats.org as the subdomain and email address for my mac's admin account.

So what do you need to do?

*/ Setup postfix
*/ setup google
*/ setup DNS
*/ setup site verification (web)
*/ setup site verification (mail)
*/ Profit

Setup postfix

You'll need to setup a Simple Authentication and Security Layer (SASL)

vi /etc/postfix/sasl_passwd

with the following:
smtp.gmail.com:587 your.name@gmail.com:your.password

Create a postfix lookup table for SASL:
postmap /etc/postfix/sasl_passwd

Configure postfix with:

vi /etc/postfix/main.cf

with the following:
# Minimum Postfix-specific configurations.
mydomain_fallback = localhost
mail_owner = _postfix
setgid_group = _postdrop
relayhost=smtp.gmail.com:587
# Enable SASL authentication in the Postfix SMTP client.
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options=

# Enable Transport Layer Security (TLS), i.e. SSL.
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom

Setup google


This will involve going into your dashboard - just google "google apps"
add your (sub) domain into the domain tab of settings.

Setup DNS

Point DNS to a webserver that you own 

Setup site verification (web)

This will involve placing a specially crafted text file (supplied by google) onto that site


Setup site verification (mail)

This will involve adding a TXT record for the above (sub)domain

Profit

Monday, 24 October 2011

vim stuff

Make vim more usable by putting these in your .vimrc 

set background=dark
set ignorecase
set number
set fo=tcq
set nocompatible
set modeline

syntax on

" set default comment color to cyan instead of darkblue
" which is not very legible on a black background
highlight comment ctermfg=cyan

set tabstop=4
set expandtab
set softtabstop=4
set shiftwidth=4

highlight LiteralTabs ctermbg=darkgreen guibg=darkgreen
match LiteralTabs /\s\  /
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen
match ExtraWhitespace /\s\+$/

" Show me a ruler
set ruler

" Set up puppet manifest and spec options
au BufRead,BufNewFile *.pp
  \ set filetype=puppet
au BufRead,BufNewFile *_spec.rb
  \ nmap <F8> :!rspec --color %<CR>

" Enable indentation matching for =>'s
filetype plugin indent on


Monday, 26 September 2011

Check_MK clustered services

The documentation for check is old!
Following the clustered services docs won't work, so what you have to do is this:

1/ Define your clusters in main.mk, Don't define it in a separate clustered_services.mk file
2/ Define clusters like so:

clusters.update({
'lon-stasql02.vm.prod|win|mssql': ['lon-sta02a.vm.prod','lon-sta02b.vm.prod'],
})

3/ Defline clustered services like so:
clustered_services_of ['lon-stasql02.vm.prod'] = [( ALL_HOSTS,[ 'fs_D:/', 'fs_E:/','fs_F:/','fs_G:/','fs_H:/','fs_I:/','fs_J:/','fs_K:/','fs_L:/','fs_M:/','fs_N:/','fs_O:/','fs_P:/','fs_Q:/','fs_X:/','fs_Y:/','fs_Z:/', 'proc_SQL Agent', 'service_MSSQLSERVER']),]

4/ Then when inventorying, you MUST inventory all nodes in one shot, otherwise it will not add them to the cluster.

check_mk -uII lon-sta02a.vm.pro lon-sta02b.vm.prod
check_mk -O

5/ Note that this must all be defined in your main.mk
Done!

Wednesday, 7 September 2011

Event handlers for Check_mk

main.mk :

all_hosts = [
"myhost|myflag" ,
]

# Enable event handlers for services which prefixes are those seen in the Nagios WI
# Nagios check is identified here as "Legacy_MYSQL" (legacy check)

extra_service_conf["event_handler_enabled"] = [
 ( "1", ALL_HOSTS, ["Legacy_MYSQL"] )
]

# "restart-mysql" and as the event handler command

extra_service_conf["event_handler"] = [
 ( "restart-mysql",ALL_HOSTS, ["Legacy_MYSQL"] )
]

# Define check plugin and event handler command
# See Nagios online documentation examples http://nagios.sourceforge.net/docs/nagioscore/3/en/eventhandlers.html
# and set up according your distro

extra_nagios_conf += r"""

define command{
        command_name    check_mysql_database
        command_line    $USER1$/check_mysql -d '$ARG3$' -H '$HOSTADDRESS$' -u '$ARG1$' -p '$ARG2$'
}

define command{
        command_name    restart-mysql
        command_line    /usr/local/nagios/libexec/eventhandlers/restart-mysql  $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
        }

"""

legacy_checks = [
  ( ( "check_mysql_database!dbuser!dbpwd!dbname!", "Legacy_MYSQL : Mysql Database dbname", False), [ "myflag" ], ALL_HOSTS ),
]

Set appropriate owner and group to event handler command and then grant permissions to the Nagios user in /etc/sudoers file to perform the system command.

Find new services and reload Nagios : cmk -I && cmk -O

Output Nagios configuration with cmk -N  to check event handler parameters:

define service {
  use                check_mk_default
  host_name            myhost
  service_description        Legacy_MYSQL : Mysql Database dbname
  check_command            check_mysql_database!dbuser!dbpwd!dbname!
  active_checks_enabled        1
  service_groups        +legacy
  event_handler_enabled         1
  event_handler                 restart-mysql
}

Tuesday, 6 September 2011

Vim: How to delete the first n characters from every line or region


deletes the first 5 characters of every line

:%s/^.\{5}//gic


Alternatively:

:v
visual mode, then
0
then CTRL +V for visual block
tada!

Monday, 5 September 2011

kexec and how to do a cold reboot without editing the kexec default file

just issue the coldreboot command to reboot without using kexec :D

That binary is part of the kexec-tools package