Sturbi's Home

  • Gallery
  • Modellflug
  • Datenschutz
  • Impressum

Blog

  • Allgemein (15)
    • Sprüche (6)
  • Angeln (3)
  • Computer (25)
    • Linux (16)
      • Nagios (5)
      • Nginx (4)
      • Postfix (3)
      • Subversion (1)
    • VMware (3)
    • Windows (9)
      • Powershell (8)
  • Fotografie (26)
  • Reise (8)
    • Hawaii (4)
    • Irland (1)
    • USA (5)
Wenn du etwas so machst,
wie du es seit zehn Jahren gemacht hast,
dann sind die Chancen groß,
daß du es falsch machst.

Charles F. Kettering amerikanischer Ingenieur * 29.08.1876, † 25.11.1958

Nagios + check_mk Part 1 – ESXi

9. Oktober 2012 by Sturbi Kategorie: Nagios

Diese Blogposts sind eigentlich nur für mich, um ein paar Konfigurationen zu dokumentieren 😉

Benutzt wird das check_esx.pl von op5 http://www.op5.org/community/plugin-inventory/op5-projects/check-esx-plugin

Check Kommand Definitionen sind sowohl in der commands.cfg von Nagios als auch in der main.mk gültig:

extra_nagios_conf += r"""

// place legacy check commands here

"""
define command{
    command_name    check-esx-datacenter
    command_line    $USER2$/check_esx.pl -D 'vcenter' --extra-opts=check_esxi@/opt/omd/sites/nag/etc/nagios/plugins.ini -l $ARG1$
}

define command{
    command_name    check-esx-vm
    command_line    $USER2$/check_esx.pl -D 'vcenter' -N $ARG1$ -l $ARG2$ --extra-opts=check_esxi@/opt/omd/sites/nag/etc/nagios/plugins.ini
}

define command{
    command_name    check-esx-host
    command_line    $USER2$/check_esx.pl -H $HOSTADDRESS$ -l $ARG1$ --extra-opts=check_esxi_host@/opt/omd/sites/nag/etc/nagios/plugins.ini
}

define command{
    command_name    check-esx-host-sub
    command_line    $USER2$/check_esx.pl -H $HOSTADDRESS$ -l $ARG1$ -s $ARG2$ <a>--extra-opts=check_esxi_host@/opt/omd/sites/nag/etc/nagios/plugins.ini</a>
}

legacy_checks Definition in der main.mk:

legacy_checks = [
  (( "check-esx-datacenter!runtime", "ESXi VCenter Runtime", True ), [ "vcenter" ] ),
  (( "check-esx-host!cpu", "ESXi Host CPU", True ), [ "esx" ], ALL_HOSTS ),
  (( "check-esx-host!mem", "ESXi Host Speicher", True ), [ "esx" ], ALL_HOSTS ),
  (( "check-esx-host!net", "ESXi Host Netzwerk", True ), [ "esx" ], ALL_HOSTS ),
  (( "check-esx-host!io", "ESXi Host IO", True ), [ "esx" ], ALL_HOSTS ),
  (( "check-esx-host!runtime", "ESXi Host Runtime", True ), [ "esx", ALL_HOSTS ] ),
  (( "check-esx-host!vmfs", "ESXi Host vmfs", True ), [ "esx" ], ALL_HOSTS ),
  (( "check-esx-host!service", "ESXi Host Service", False ), [ "esx" ], ALL_HOSTS ),
  (( "check-esx-host-sub!vmfs!ISOStore", "ESXi Host ISO Store", True ), [ "esxi" ], ALL_HOSTS ),
  (( "check-esx-host-sub!vmfs!VMStore1", "ESXi Host VM Store 1", True ), [ "esxi" ], ALL_HOSTS ),
  (( "check-esx-host-sub!vmfs!VMStore2", "ESXi Host VM Store 2", True ), [ "esxi" ], ALL_HOSTS ),
  (( "check-esx-host-sub!vmfs!VMStore3", "ESXi Host VM Store 3", True ), [ "esxi" ], ALL_HOSTS ),
]

plugin.ini:

[check_esxi]
username=DOMAIN\Nagios
password=geheimespasswort

[check_esxi_host]
username=root
password=nochvielgeheimer

Limit Postfix E-Mails pro Stunde

26. Juli 2012 by Sturbi Kategorie: Linux, Nagios, Postfix

Nachdem aus dem OTRS in der Nacht 25.000 E-Mails versand wurden, hatte uns unser Provider vorübergehend auf seinen Relay Servern blacklistet.
Um solche nächtliche Überraschungen künftig zu vermeiden, habe ich einen Policy Server für Postfix geschrieben. Dieser wird auf dem ausgehenden Mail Relay eingebunden und gibt nach 750 E-Mails pro Stunde dem Exchange DEFER zurück gibt, worauf dieser die Mails in seiner Queue behält.

Der Policy Server liest aus der Datei /tmp/postfix-counter den aktuellen Count und den Timestamp des letzten Counterreset. Ist der Timestamp älter als eine Stunde, wird der Counter auf 1 gesetzt, sonst um 1 erhöht und wieder in die Datei zurückgeschrieben.

Zur Überwachung habe ich einen einfachen Nagios Check geschrieben, welcher den Counter ausliest, die Anzahl Mails prüft und als Performancedaten ausgibt. Die enstandenen PNP Graphen sehen dann wie Sägezähne aus.

Im Postfix wird das Ganze in der main.cf eingebunden.

smtpd_recipient_restrictions = permit_mynetworks check_policy_service inet:127.0.0.1:8895 reject_unauth_destination

 

#! /usr/bin/perl -W
# based on sample from Postfix Page

use strict;
use Errno;
use IO::Select;
use IO::File;

my $fds;
my $flog;
my $conffile;
my %times = ();
my $maxcount = 750; # max mail per hour

sub init_sockets;

# initialize anything (database etc)
sub init() {
  $fds = IO::Select->new() or die "unable to create IO::Select object\n";
  init_sockets('inet:127.0.0.1:8895');
  use IO::File;
  $flog = IO::File->new("/tmp/smtpd-policy.log", 'a');
}

init();

sub request($;$) {
  my ($attr,$sock) = @_;
  my $act = 'DUNNO';
  my $now = time;

  open(FILE, "/tmp/postfix-counter");

  while(<FILE>){
    chomp($_);
    my ($key, $val) = split(/:/, $_);
      $times{$key} = $val;
    }

  close(FILE);  

  if ($times{'1htime'} + 3600 > $now){
    if ($times{'1hcount'} < $maxcount){
      my $tmp = $times{'1hcount'};
      $tmp = $tmp + 1;
      $times{'1hcount'} = $tmp;
      $act = 'OK';
      $times{'now'} = $now;
    }else{
      $act = 'DEFER to many mail';
      $times{'now'} = $now;
    }
  }else{
    $times{'1htime'} = $now;
    $times{'1hcount'} = 1;
    $act = 'OK';
    $times{'now'} = $now;
  }

  open(FILE, ">/tmp/postfix-counter");
  for my $key ( keys %times ) {
    my $value = $times{$key};
    print FILE "$key:$value\n";
  }

  close(FILE);

  if (defined $flog) {
    $flog->print("request:");
    $flog->print(" $_=$attr->{$_}") foreach keys %$attr;
    $flog->print(" action=$act\n");
    $flog->flush;
  }
  $act;
}

sub request_cb($) {
  my $s = shift;
  my $r = ${*$s}{attrs} || ( ${*$s}{attrs} = {} );
  for(;;) {
    $_ = $s->getline;
    unless (defined $_) {
      $fds->remove($s) unless $!{EAGAIN};
      return;
    }
    if (/^([a-zA-Z_]+)=([^\r\n]*)\r?\n$/) { $r->{$1} = $2; }
    elsif (/^\r?\n$/) { last; }
    else { $r->{error} = 1; }
  }
  ${*$s}{attrs} = undef;
  my $act;
  if ($r->{error}) { $act = 'ERROR unknown request line'; }
  elsif (!exists($r->{request}) ||
         $r->{request} ne 'smtpd_access_policy') {
    $act = 'ERROR required request attribute is not present';
  }
  else {
    $act = request($r);
    unless (defined $act) {
      $fds->remove($s);
      return;
    }
  }
  $s->print("action=$act\n\n") or $fds->remove($s);
}

sub accept_cb($) {
  my $ls = shift;
  my $s = $ls->accept;
  if ($s) {
    $s->blocking(0);
    ${*$s}{cb} = \&request_cb;
    $fds->add($s);
  }
}

sub init_sockets {
  foreach my $sock ( @_ ) {
    my $s;
    if ($sock =~ /^inet:([^:]+:.+)$/i) {
      use IO::Socket::INET;
      $s = IO::Socket::INET->new(
        LocalAddr => $1,
        Proto => 'tcp',
        Type => SOCK_STREAM,
        Listen => 5,
        ReuseAddr => 1,
      );
    }
    elsif ($sock =~ /^unix:(.+)$/) {
      use IO::Socket::UNIX;
      unlink $1;
      $s = IO::Socket::UNIX->new(
        Type => SOCK_STREAM,
        Local => $1,
        Listen => 5,
      );
    }
    else {
      die "invalid listening point specification: $sock\n";
    }
    die "unable to create listening socket for $sock: $!\n" unless $s;
    $s->blocking(0);
    ${*$s}{cb} = \&accept_cb;
    $fds->add($s);
  }
}

for(;;) {
  foreach my $s ( $fds->can_read() ) {
    &{${*$s}{cb}}($s);
  }
}

 

Exchange Message Header cleanup in Postfix

19. Juli 2012 by Sturbi Kategorie: Linux, Postfix, Windows

Wer sich mal den Header seiner ausgehenden E-Mail angesehen hat, wird vielleicht mit Schrecken festgestellt haben, das Exchange Server dort etwas zu gesprächig sind.
Da man für eine DKIM Signatur am besten noch ein ausgehendes Relay zwischen Exchange und Internet schaltet, kann man mit Postfix sehr schnell für Abhilfe schaffen.
Die DKIM Signatur erfolgt nach der Verarbeitung der „header_checks“, wir können hier also noch beliebig ändern.

Zuerst ersetze ich die „Received“ Zeile der Übertragung vom Exchange Server an das Postfix Relay mit einem Eintrag von localhost. Hier kann man auch einen beliebigen anderen MTA z.B. Exim eintragen. Er sollte nur nicht zu fantasievoll sein, Antispam Systeme sind nachtragend. Das gilt auch für die unbedingt richtige Syntax! (MessageID und Uhrzeit)

Dann werden alle X-Header mit Verweisen auf interne IP Adressen gelöscht.

Zuletzt lösche ich noch X-Header mit Verweisen auf den User-Agent, Antivirus und Antispam und wer sich da sonst noch einträgt.
Benutzt man z.B. OTRS, sollte man hier unbedingt den X-Header mit der Software Versionsnummer löschen, aber den X-Header mit der Ticketnummer lassen.

zum testen legt man sich ein Mailkonto bei hotmail an und schaut sich dort den Quelltext der E-Mail an.

 

header_checks = pcre:/etc/postfix/header_checks

 

/^Received: from exchange.intern.sturbi.de (.*) with ESMTP id ([A-F[:digit:]]+)(.*)/    REPLACE Received: from [127.0.0.1] (localhost [127.0.0.1]) by [127.0.0.1] (Postfix) with ESMTP id $2 $3
/^Received: (.*)192\.168/       IGNORE
/^Received: (.*)10\.0/  IGNORE
/^Received: (.*)172\./  IGNORE
/^X-Virus/ IGNORE
/^X-Mailer/ IGNORE
/^User-Agent/ IGNORE
/^X-MS-Has-Attach/ IGNORE
/^X-MS-TNEF-Correlator/ IGNORE
/^X-OLX-Disclaimer/ IGNORE
/^X-Powered-BY: OTRS/ IGNORE
/^X-Virus/              IGNORE
/^X-Mailer/             IGNORE
/^User-Agent/           IGNORE
/^X-MS/      IGNORE
/^x-originating-ip/      IGNORE

Enable SNMP on VMWare ESXi5

25. Februar 2012 by Sturbi Kategorie: Nagios, Powershell

Download and install „vSphere PowerCLI“

[ps]Connect-VIServer -Server esxihost
$hostSNMP = Get-VMHostSNMP
Set-VMHostSNMP $hostSNMP -Enabled:$true -ReadOnlyCommunity 'secret'[/ps]

Nagios, Mailgraph, check_logfile

8. April 2011 by Sturbi Kategorie: Linux, Nagios, Postfix

zur Statistischen Erfassung war auf dem alten Mailserver „mailgraph“ installiert. Das Problem für mich war, das ich die Daten nicht brauchbar ins Nagios bekommen habe (check_rrd etc).
Die Lösung: Das Maillog mit check_logfile parsen und das Ergebniss als Performance Daten für Nagios ausgeben.

Aufruf von check_logfile in der nrpe.cfg:
command[check_mailflow]=sudo /usr/lib/nagios/plugins/check_logfiles -f /etc/nagios-plugins/config/logfile.cfg
In der logfile.cfg sind die Parser für

  • recive – Mail an den Exchange weitergeleitet
  • bounce – allgemeine Bounces
  • block – durch RBL geblocke Mails
  • block-nouser – wegen ungültiger Benutzer geblockte Mail
our $sendcount = 0;
our $bouncecount = 0;
our $blockcount = 0;
our $nousercount = 0;

@searches = ({
tag => 'postfix',
logfile => '/var/log/mail.log',
rotation => 'loglogdate8gz',
options => 'supersmartscript,noprotocol,supersmartpostscript',
criticalpatterns => '.*',
script => sub {

if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\bstatus=sent\b/){
if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} !~ /\brelay=[^\s\[]*\[127\.0\.0\.1\]/ ){
$sendcount++;
}
}

if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\bstatus=bounced\b/) {
$bouncecount++;

}

if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\b.*NOQUEUE: .*reject: .*: 554.* blocked using\b/) {
$blockcount++;

}

if ( $ENV{CHECK_LOGFILES_SERVICEOUTPUT} =~ /\b.*NOQUEUE: .*reject: .*: 550.* Recipient address rejected\b/) {
$nousercount++;

}

},

});
$options = 'supersmartpostscript';

$postscript = sub {
my $tic = $CHECK_LOGFILES_PRIVATESTATE->{postfix}->{lastruntime} || 0;
my $tac = time;
my $runtime = ($tac - $tic);

my $sendrate = 60 * ( $sendcount / $runtime );

printf "OK - recive: %.1f bounce: %.1f block: %.1f block-nouser: %.1f | recive=%.1f;bounce=%.1f;block=%.1f;block-nouser=%.1f\n", $sendra
te, $bouncecount, $blockcount, $nousercount, $sendrate, $bouncecount, $blockcount, $nousercount;

return 0;

PHP 5.3.3 PHP-FPM für Nginx compilieren

7. November 2010 by Sturbi Kategorie: Linux, Nginx

Nachdem ja wie angekündigt in PHP 5.3.3 FPM fest integriert ist, habe ich also meinen Server umgestellt.
PHP 5.3.3 herunterladen und dann geht irgendwie alles nach Standardprozedur ...

tar xvfz php-5.3.3.tar.gz
cd php-5.3.3
./configure --prefix=/usr/local --sysconfdir=/etc/php --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --with-mhash --with-xsl --with-pcre-regex --with-mysqli --with-mysql --enable-exif --with-gd --with-ldap --with-pdo-mysql --with-bz2 --with-t1lib --with-jpeg-dir=/usr --with-png-dir=/usr --with-gettext
make
make install

Die notwendigen Anpassungen an der php-fpm.conf sind äquivalent eines gepatchten 5.2.
Gestartet wird der FPM Prozess dann über:

/usr/local/sbin/php-fpm

Was auffällt, das keine pear und pecl bei der Installation dabei sind. Ich habs dann irgendwie doch noch von Hand nachinstalliert bekommen.

cd pear/
phar install-pear-nozlib.phar
php fetch.php
make install-su
phar go-pear.phar
phar extract -f go-pear.phar

  • « Vorherige Seite
  • 1
  • 2
  • 3
  • Nächste Seite »

© 2026 · Sturbi's Home