SSD Wear Leveling Indicator check

For our organization I wrote a script we use with Nagios to check SSD Wear Level for our Intel and Samsung SSDs. We use the output of the script to determine if an SSD needs replacement.

It can be found here:

Posted in Uncategorized | Leave a comment

Analog Mbit meter

I’ve picked up the idea of an analog megabit meter from Their talking about making a DIY kit, but the device is pretty simple. I decided not to wait and build one my own. This meter is basically an ‘Internet bandwidth meter’ which shows your bandwidth usage on a oldskool analog meter, like shown here:

Megabit Meter

The original on lacks the basic schematic and a new meter face. I’ve just used a 10k potentiometer to adjust the meter. Furthermore I’ve created a new meter face in InkScape. This face can be downloaded here.

Your shopping list is:
Analog meter: Conrad PID: 120879-8Z
10k Potentiometer: Conrad PID: 432024-8A
Arduino Nano:

I’ve also made some improvements on the Perl script that uses. Their version calculates the bytes transferred within one second. This made my meter fluctuate alot so I’ve build my own PHP script that does the same thing, but instead uses the average of the last 5 calculations as meter value. This makes the meter less jumpy. The code is:


function microtime_float()
 list($usec, $sec) = explode(" ", microtime());
 return preg_replace("/\./", "", $usec + $sec);

function getBytes()
 $handle = @fopen("/sys/class/net/eth0/statistics/rx_bytes", "r");
 if ($handle) {
 while (($buffer = fgets($handle, 4096)) !== false) {
 return preg_replace("/\n/", "", $buffer);

function average($input) {
 return round(array_sum($input) / count($input), 0);

$oldValue = getBytes();
$gemiddelden = array(0, 0, 0, 0, 0, 0, 0, 0, 0);

$value = 1000000; // 1s
$value = 250000;

while (true) {
 $curValue = round(((getBytes() * 8) / $value), 0);

 $averageValue = average($gemiddelden);
 $newValue = round($curValue - $oldValue, 0);

 array_push($gemiddelden, $newValue);

 if (average($gemiddelden) > 100) {
 echo "100\n";
 } elseif (average($gemiddelden) < 0) {
 echo "0\n";
 } else {
 echo average($gemiddelden) . "\n";

 $oldValue = $curValue;



Posted in Uncategorized | 1 Comment

Muting Audio/Video Equipment

IRTrans LAN ControllerI’m a big fan of domotica, so I got myself a IRTrans module. This module connects to your Ethernet network and allows you to send/receive IR commands. This little gadget is hooked up to my HomeSeer computer. I also wrote a little script that hooks into my PBX.

My Audio/Video equipment is now turned off when I arm my alarm system and is muted/paused when I receive an incoming call. When someone presses my doorbell the system is only paused. The connection with the alarm system and the doorbell can be easily arranged with some HomeSeer events. The PBX connection was a little bit more difficult.

I am using the Asterisk manager system. A little PHP scripts connects to the Manager interface and ‘listens’ for new calls. It then verifies if the call is to or from a phone in my livingroom, and if so mutes the audio/video using the IRTrans IRClient tool.

The script can be found here: Link

Posted in Uncategorized | Leave a comment

PowerDNS AXFR broken with IPv6

Having IPv6 enabled on our nameservers, I’ve noticed that new domains where no longer slaved. We use PowerDNS’s supermaster feature for this, which basicly means it verifies NOTIFY messages against a list of ‘trusted masters’, if the sender address of the NOTIFY message matches any of the trusted masters it automaticly creates the new domain as a slave domain and performs an AXFR-query on the master to retrieve the zonefile.

When using IPv6 with PowerDNS, the PowerDNS server ‘pdns’ binds to its port with AF_INET6. By default, AF_INET6 binds to both IPv4 and IPv6 and uses v4-in-v6 mapping. If a IPv4 connection is made the address is in the form of “::ffff:′.

The problem is that it is not possible to open a IPv6 connection to “::ffff:”. However, this is wat pdns wants to to to query the supermaster server. The resulting error is:

Error resolving SOA or NS at: ::ffff: Unable to ask query of ::ffff: Address family not supported by protocol

The solution is to set the sysctl setting to ‘1’. If set, this makes AF_INET6 sockets only listening on IPv6 addresses thus disabling the v4-in-v6 mapping.

Furthermore you have to make sure that PowerDNS is explicitly configured to listen on your IPv4 address with “local-address=” and your IPv6 address with “local-ipv6=”.

Then everything should be okay again.

Posted in Uncategorized | Leave a comment

Plesk & IPv6

The last few days I’ve been busy implementing IPv6 on some of our servers. Most software supports IPv6 out of the box like BIND, PowerDNS, Postfix, Apache, etc, etc. I’ve configured IPv6 on all of our machines and it all works like a charm. However, all our customer’s sites are hosted on machines which run the Parallels Plesk control panel and Plesk does not support IPv6 at all. Even worse, the Plesk-customized packages like Courier have IPv6 disabled at compile time.

According to what I’ve found a standard Plesk 9 server (Linux) has IPv6 support for:

  • BIND (Default package)
  • Apache (Default package)
  • Postfix (Default package, Exim does not support IPv6)

The only important package which lacks IPv6 support is Courier.

Plesk itself does not support IPv6 at all, but most of its daemons do. So I worked on implementing it myself with a little PHP script.

You can use this script to run every 1 to 5 minutes or so. What it does is scan the /var/www/vhosts/ directory for domains, check if the httpd.include file requires modification (to enable IPv6) and if it made changes it reloads your Apache configuration.

What you need to do next is:

  • Add AAAA-records to your zonefiles
  • Add a NameVirtualHost directive in your Apache configuration for the IPv6 address
  • add “inet_protocols = all” to your /etc/postfix/ to enable IPv6 in Postfix
  • Have BIND listen to your IPv6 address (no details here, I dont use the Plesk DNS server)

And your ready to go!

If for some reason this script does not work for you, and everything goes foobar you can restore the original Plesk configuration files with a easy Plesk command:

/opt/psa/admin/bin/websrvmng -a

This utility regenerates the vhost configuration files.

The script can be found here.

(Disclamer: I didn’t test it. It works for me. Quite possibly not the best piece of code you’ve ever seen).

Posted in Uncategorized | 1 Comment