UPWORK/ODESK guru: Tips and Tricks for clients

skype: upwork.link , email: [email protected]

Archive for November, 2012

Keeping packages neatly wrapped up or How to use local Perl modules on public hosting.

without comments

Who the heck installed WWW::AdventCalendar on the server?

Imagine this not-exactly-hypothetical conversation:

1
2
3
4
5
6
7
8
  <Alice> Who the heck installed WWW::AdventCalendar on the server?
  <Bob>   I did.  Why?
  <Alice> We're trying to set up a new server just like it, and we found
          this installed, and it wants all kinds of crazy prerequisites.
          Why on Earth do we need this in production?
  <Bob>   Oh, we don't.  I just wanted to play around with it.
  <Alice> ...so you installed it globally?
  <Bob>   Well, how else was I going to play with it?

Read the rest of this entry »

Written by spectre

November 16th, 2012 at 3:20 pm

Posted in Perl

Regular expression to match string not containing a word.

without comments

The fact that regex doesn’t support inverse matching is not entirely true. You can mimic this behavior by using negative look-arounds:

1
^((?!hede).)*$

The regex above will match any string, or line without a line break, not containing the (sub) string ‘hede’.As mentioned, this is not something regex is “good” at (or should do), but still, it is possible.

Explanation

Read the rest of this entry »

Written by spectre

November 15th, 2012 at 9:34 pm

Posted in Perl

Protected: How to Postfix effectively blocks spam on config level.

without comments

This content is password protected. To view it please enter your password below:

Written by spectre

November 12th, 2012 at 7:41 pm

Posted in Postfix & Amavis

DROP ALL TABLES в MySQL

without comments

The heading at this note is a bit wrong. In MySQL there is no such command, and it would be desirable, that it was. Sometimes there are problems in which we want to remove all tables of a DB, but not her (that there were its parametres, such as access rights, codings, etc.). To solve such problem it is possible with the help command:

a=name;b=pass;c=base;mysqldump -u$a -p$b --add-drop-table --no-data $c|grep ^DROP|mysql -u$a -p$b $c

The first command of the conveyor we create «dump» the databases, consisting of every possible DROP TABLE, but without the data. The second command we choose only the lines beginning with DROP, and at last, we fill in the received commands in MySQL.

Written by spectre

November 10th, 2012 at 2:15 pm

Protected: How to use postfix and policyd daemon.

without comments

This content is password protected. To view it please enter your password below:

Written by spectre

November 7th, 2012 at 4:11 pm

Posted in Postfix & Amavis

Monitor Varnish with Zabbix

without comments

Add the following to the end of /etc/zabbix/zabbix_agentd.conf
# Varnish Keys
UserParameter=varnish.stat[*],(test -f /usr/bin/varnishstat && varnishstat -1 -f $1 | awk ‘{print $$2}’)

Restart the Zabbix agent
/etc/init.d/zabbix-agent restart

Written by spectre

November 5th, 2012 at 10:35 pm

Posted in Zabbix

Monitor SELinux with Zabbix

without comments

Add the following to the end of /etc/zabbix/zabbix_agentd.conf
# SELinux Keys
UserParameter=selinux.status,/usr/sbin/sestatus | grep status | awk ‘{print $NF}’ | sed s/enabled/1/ | sed s/disabled/0/
UserParameter=selinux.mode,if [[ $(/usr/sbin/sestatus | egrep “status.*enabled”) ]]; then /usr/sbin/sestatus | grep mode | awk ‘{print $NF}’ | sed s/enforcing/1/ | sed s/permissive/0/; else echo 2; fi
UserParameter=selinux.boolean[*],if [[ $(/usr/sbin/sestatus | egrep “status.*enabled”) ]]; then /usr/sbin/sestatus -b | grep “^$1 ” | awk ‘{print $NF}’ | sed s/off/0/ | sed s/on/1/; else echo 2; fi

Restart the Zabbix agent
/etc/init.d/zabbix-agent restart

Written by spectre

November 5th, 2012 at 10:33 pm

Posted in Zabbix

Monitor PostgreSQL with Zabbix

without comments

Submitted by bchavet on Mon, 01/16/2012 – 17:33
# PostgreSQL Keys
UserParameter=psql.version,/usr/bin/psql –version | head -n 1
UserParameter=psql.size,/usr/bin/psql -t -c “select sum(pg_database_size(datid)) as total_size from pg_stat_database”
UserParameter=psql.stat[*],/usr/bin/psql -t -c “select sum($1) from pg_stat_database”
‹ Monitor Nginx with Zabbix

Written by spectre

November 5th, 2012 at 10:32 pm

Posted in Zabbix

Monitor Nginx with Zabbix

without comments

Configure a new nginx server listening on an alternate port (61709 in this example). This allows access to this information to be controlled.
server {
listen 61709;

location / {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

}

Reload Nginx
/etc/init.d/nginx reload

Add the following to the end of /etc/zabbix/zabbix_agentd.conf
#Nginx Keys

# NginX Keys
UserParameter=nginx.active[*],wget -O- -q $1:$2 | awk ‘/^Active/ {print $NF}’
UserParameter=nginx.reading[*],wget -O- -q $1:$2 | awk ‘/Reading/ {print $$2}’
UserParameter=nginx.writing[*],wget -O- -q $1:$2 | awk ‘/Writing/ {print $$4}’
UserParameter=nginx.waiting[*],wget -O- -q $1:$2 | awk ‘/Waiting/ {print $$6}’
UserParameter=nginx.accepted[*],wget -O- -q $1:$2 | awk ‘/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$1}’
UserParameter=nginx.handled[*],wget -O- -q $1:$2 | awk ‘/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$2}’
UserParameter=nginx.requests[*],wget -O- -q $1:$2 | awk ‘/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$3}’

Restart the Zabbix agent
/etc/init.d/zabbix-agent restart

To use these UserParameters, set the host (localhost) and port (61709) in the key
nginx.active[localhost,61709]

Written by spectre

November 5th, 2012 at 10:31 pm

Posted in Zabbix

Monitor Memcached with Zabbix

without comments

Insert the following to the end of /etc/zabbix/zabbix_agentd.conf.d/memcached.conf

UserParameter=memcached.stats[*],(echo stats; sleep 0.1) | telnet localhost 11211 2>&1 | awk ‘/STAT $1/ {print $NF}’

Written by spectre

November 5th, 2012 at 10:29 pm

Posted in Zabbix