środa, 24 grudnia 2008

check_pgpool - nagios plugin for pgpool-II

check_pgpool.rb - simple nagios plugin to check pgpool nodes status with pcp_node_info. Usefull to monitor are all nodes conneted.

checkcommands.cfg:

define command {
command_name check_pgpool
command_line $USER1$/check_pgpool.rb $ARG1$
}


services.cfg:

define service {
use generic-service
host_name pool.hostname
service_description PGPOOL1
is_volatile 0
check_period 24x7
max_check_attempts 4
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_interval 960
notification_period 24x7
check_command check_pgpool!1
}

środa, 17 grudnia 2008

PostgreSQL tricks with broken db

Few PostgreSQL tricks for broken db:

case:

pg_dump: query returned 0 rows instead of one: SELECT typlen, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze, typinput::pg_catalog.oid as typinputoid, typoutput::pg_catalog.oid as typoutputoid, typreceive::pg_catalog.oid as typreceiveoid, typsend::pg_catalog.oid as typsendoid, typmodin::pg_catalog.oid as typmodinoid, typmodout::pg_catalog.oid as typmodoutoid, typanalyze::pg_catalog.oid as typanalyzeoid, typdelim, typbyval, typalign, typstorage, pg_catalog.pg_get_expr(typdefaultbin, 'pg_catalog.pg_type'::pg_catalog.regclass) as typdefaultbin, typdefault FROM pg_catalog.pg_type WHERE oid = '1325300'::pg_catalog.oid

solution:

reindexdb -h localhost -U postgres db_name


case:

pg_dump: Error message from server: ERROR: catalog is missing 4 attribute(s) for relid 1325439

solution:

REINDEX TABLE pg_catalog.pg_attribute;


case:

pg_dump: failed sanity check, parent table OID 16401 of pg_rewrite entry OID 16403 not found

solution:

delete from pg_rewrite where oid = 16403;
REINDEX TABLE pg_catalog.pg_rewrite;

wtorek, 2 grudnia 2008

Amazon CloudFront in Ruby

Last month Amazon launch new service - Amazon CloudFront. Amazon CloudFront delivers your content from Amazon S3 using a global network of edge locations. Sweet, really nice solution for quite expensive Akamai (yes, I know Akamai is cheaper at some level, but startups don't have such budget). At start they release only Amazon CloudFront Authentication Tool for Curl. So decide to wrote own tool in ruby (atm there is RightScale Ruby library but when I wrote that there wasn't any such tool).

First, I try use curb (Libcurl bindings for Ruby), but then notice that can be done more simple only with Net::HTTP

According to Developer Guide correct REST Requests needs URI indicates the particular resource you want to act on, also needs correct Request Headers (Authorization, Content-Length, Content-Type, Date, Host, x-amz-date).

Date/x-amz-date like at provided by Amazon curl script, get from Amazon server:

def self.server_date(url)
server_date=''
uri = URI.parse(url)
http = Net::HTTP.new(uri.host,443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response=http.request_get(uri.path)
response['Date']
end


Authorization generate as Amazon documentation said:

def self.sign(date)
digest = OpenSSL::Digest::Digest.new('sha1')
hmacd=HMAC.new(AWS_SECRET_ACCESS_KEY, digest)
hmacd.update(date)
signature=Base64.encode64(hmacd.digest)
end


So simple list distribution can be done like that:

def ACFList(url)
date=server_date(url)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host,443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
headers = {
'X-AMZ-Date' => date,
'Authorization' => 'AWS ' + AWS_ACCESS_KEY_ID + ':' + sign(date).chop
}
response=http.request_get(uri.path,headers)
response
end


Example:

./acf.rb list https://cloudfront.amazonaws.com/2008-06-30/distribution
<?xml version="1.0"?>
<DistributionList xmlns="http://cloudfront.amazonaws.com/doc/2008-06-30/"><Marker></Marker><MaxItems>100</MaxItems><IsTruncated>false</IsTruncated></DistributionList>


Hole code can be find here

poniedziałek, 1 grudnia 2008

Kreatywna matematyka według Tesco

Dzisiaj w Tesco odkryłem nową, kreatywną wersje matematyki. Idąc między regałami zauważyłem:



Ser Philadelphia - 3,29zł (ta mała cena po lewej stronie). Promocja 2 sztuki za 6zł. Niby ok, jest promocja jest dobrze. Niepokoi mnie tylko informacja "Oszczędzasz 6zł"

WTF ?!?

2x3,29zł = 6,58zł
- 6,00zł
-----------------
0,58zł (nijak 6zł nie wychodzi)

Idąc za ciosem zrobiłem jeszcze kilka zdjęć: