OTRS and Nagios integration – to be tested


Contents

-Email
-1)Attachment (NagiosGenericAgent.pl): application/x-perl, 12 KiB
-2)Attachment (otrs_ticket_handler.pl): application/x-perl, 3939 bytes
Source: http://permalink.gmane.org/gmane.comp.otrs.devel/813
NB
No gurantee it works, to be tested on my lab sytem.

 

RE: Nagios and OTRS
Volker Maibaum <volker.maibaum <at> eberspaecher.com>
2005-01-13 15:41:37 GMT

Hi,

ok I have the install-howto and the scripts attached.

Don’t hesitate if there are any questions…

Volker

Am Donnerstag, den 13.01.2005, 14:57 +0000 schrieb Nigel Clarke:
> Yes please. Sounds like a great solution.
>
> —–Original Message—–
> From: dev-bounces <at> otrs.org [mailto:dev-bounces <at> otrs.org] On Behalf Of
> Volker Maibaum
> Sent: Thursday, 13 January 2005 2:53 PM
> To: dev <at> otrs.org
> Subject: [dev] Nagios and OTRS
>
>
> Hello,
>
> we are using nagios for system monitoring in our company. As we also use
> OTRS, I thought it would be a nice thing to make the tools work
> together. Two perl-scripts and a bit of configuration was all that was
> needed.
>
> The integration works as follows:
> When NAGIOS notices a host or service problem it starts a perl-script
> that sends an Email to OTRS. A Tickets is created by OTRS after
> recieving the message. When the problem still exists after some time,
> NAGIOS calls the script again. This time the script does not send an
> email to OTRS, but calls a modified copy of GenericAgent (over SSH) to
> add a note to the existing Ticket. When the problem has vanished NAGIOS
> calls the script again, which then closes the ticket the same way.
>
> I tried to make the scripts as independent of the OTRS-version as
> possible, but as I use a modified copy of the GenericAgent.pl there is
> problably the need to do some minor adjustments to this perl-script when
> using a different version of OTRS than 1.2.2.
>
> Is there a way to create dynamic jobs (created from commandline
> parameters) for GenericAgent? Then i could make it completely
> independend from the OTRS Version.
>
> Is anyone interested in the scripts (incl. installation-howto)?
>
> Is there a place on the otrs-page where people can make there code
> available to others? I saw that the wiki was closed…  
>
>

mit freundlichen Grüßen

Volker Maibaum

Tel: 0711-939-0972
Fax: 0711-939-160972
volker.maibaum <at> eberspaecher.com

Attachment (NagiosGenericAgent.pl): application/x-perl, 12 KiB
Attachment (otrs_ticket_handler.pl): application/x-perl, 3939 bytes
Dokumentation: Integrating OTRS with NAGIOS

The integration works as follows:
When NAGIOS notices a host or service problem it starts a perl-script that sends an Email to OTRS. A Tickets
is created by OTRS after recieving the message.
When the problem still exists after some time, NAGIOS calls the script again. This time the script does not
send an email to OTRS, but calls a modified copy of GenericAgent (over SSH) to add a note to the existing
Ticket. When the problem has vanished NAGIOS calls the script again, which then closes the ticket the same way.

I tried to make the scripts as independent of the OTRS-version as possible, but as I use a modified copy of the
GenericAgent.pl there is problably the need to do some minor adjustments to this perl-script when using a
different version of OTRS than 1.2.2.

Requirements:
OTRS 1.2.2 (small modification in NagiosGenericAgent.pl might be necessary for other versions)
NAGIOS 1.2 (should work with other Versions too. Nagios only needs to be able to call an external script when
notifying OTRS and some nagios-macros are needed)
MailTools from CPAN (on the Nagios Server, I used MailTools-1.65)

Installation Instructions:

A Configuration of the Nagios Server
————————————
1) copy the script otrs_ticket_handler.pl to (e.g.) /usr/lib/nagios/ and make this script executable
for the nagios-user
2) define commands that are used for notifications to OTRS (e.g. in /etc/nagios/misccommands.cfg)
# for service notifications
define command{
        command_name    notify-by-email_otrs
        command_line    /usr/lib/nagios/otrs_ticket_handler.pl -T s -H $HOSTNAME$ -S ‘$SERVICEDESC$’ -s
‘$SERVICESTATE$’ -N ‘$NOTIFICATIONTYPE$’ -n ‘$NOTIFICATIONNUMBER$’ -o ‘$OUTPUT$’ -C
‘$CONTACTALIAS$’ -a ‘$HOSTADDRESS$’
        }
# for host notifications
define command{
        command_name    host-notify-by-email_otrs
        command_line    /usr/lib/nagios/otrs_ticket_handler.pl -T h -H $HOSTNAME$ -S ‘__’ -s ‘$HOSTSTATE$’ -N
‘$NOTIFICATIONTYPE$’-n ‘$NOTIFICATIONNUMBER$’ -o ‘$OUTPUT$’ -C ‘$CONTACTALIAS$’ -a ‘$HOSTADDRESS$’
        }
3) Define a contact (or several contacts) for OTRS notifications (e.g. in /etc/nagios/contacts.cfg)
# alias must be the otrs-queue where the notifications for this contact should go to!!
# ‘OTRS’ contact definition
  define contact {
        contact_name                    OTRS
        alias                           my_nagios_queue
        service_notification_period     24×7
        host_notification_period        24×7
        service_notification_options    c,r,w,u
        host_notification_options       d,u,r
        service_notification_commands   notify-by-email_otrs
        host_notification_commands      host-notify-by-email_otrs
        email                           dummy <at> email.address
        }

4) Configure the otrs_ticket_handler.pl script (look at the comments in the script)

5) Allow the NAGIOS server to execute the NagiosGenericAgengt.pl script on the OTRS host:
– create a ssh key pair for the nagios user (e.g. with ssh-keygen)
– add the public key to the ~/.ssh/authorized_keys file of the otrs user on the OTRS host. (if it’s not the
create the directory and create the authorized_keys file)

B. Configuration of the OTRS server
———————————–
1) create OTRS-queues where the NAGIOS-tickets should appear. The queue names should correspond to the
contact aliases from NAGIOS (-> section A. 3) )

2) copy the NagiosGenericAgent.pl script to the OTRS host (e.g. to /opt/otrs/bin/). Make sure that it is
executable by the otrs user.

3) configure NagiosGenericAgent.pl (look at the comments!). The settings must correspond to the
TicketFreeText settings in Config.pm and otrs_ticket_handler.pl

4) configure OTRS so that it interprets the X-OTRS-Headers in emails that come from the NAGIOS host
e.g in ~otrs/.procmailrc:
# —
# Remove all X-OTRS Header (allow this only for trusted email)
# e. g. from *@example.com
# —
:0 fhw :
* !^From.*my_nagios_host.com
| grep -vi ‘^X-OTRS-‘

5) TicketFreeKey / TicketFreeText configuration in Config.pm
hostname, servicename and host-/service state are stored in these fields.
Use the same settings as in otrs_ticket_handler.pl and NagiosGenericAgent.pl   
    # host name
    $Self->{“TicketFreeKey2”} = {
        ‘Server’ => ‘Server’,
    };
    # service name
    $Self->{“TicketFreeKey3”} = {
        ‘Service’ => ‘Service’,
    };
    # host-/service state
    $Self->{“TicketFreeKey4”} = {
        ‘Service-Status’ => ‘Service-Status’,
        ‘Server-Status’ => ‘Server-Status’,
    };
_______________________________________________
OTRS mailing list: dev – Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev

 

 

 

@@@@@@@@@@@@@
@@@@@@@ Here is the version of NagiosGenericAgent.pl used@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@
@@@@@@

1) NagiosGenericAgent.pl

@@@@@@@@@

 

#!/usr/bin/perl -w
# —
# Changed Version of Generic Agent that is used for closing
# Tickets and adding Notes to Tickets
# —

#
# USAGE: GaCloseNagiosTickets.pl -h HOST -S SERVICE -s STATUS -m MESSAGE -c CLOSE
#
# if close = 1 then Ticket will be closed, otherwise a note will be added
#

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin).”/Kernel/cpan-lib”;

use strict;

use vars qw($VERSION $Debug $Limit);

use Getopt::Std;
use Kernel::Config;
use Kernel::System::Log;
use Kernel::System::DB;
use Kernel::System::Ticket;
use Kernel::System::Queue;

# configuration

my @nagios_queues = [‘nagios_test’, ‘nagios_test::or’, ‘nagios_test::krz’, ‘nagios_test::ti’, ‘nagios_test::or4’];
# Definitions for TicketFreeKeys and TicketFreeText
# (use the same settings in NagiosGenericAgent.pl !!)
# definitions for host freefield
my $host_key            = “X-OTRS-TicketKey2”;          # TicketFreeKey
my $host_text           = “X-OTRS-TicketValue2”;        # TicketFreeText
my $host_name           = “Server”;                     # Value for TicketFreeKey
# definitions for service freefield
my $service_key         = “X-OTRS-TicketKey4”;          # TicketFreeKey
my $service_text        = “X-OTRS-TicketValue4”;        # TicketFreeText
my $service_name        = “Service”;                    # Value for TicketFreeKey
# definitions for state freefield
my $state_key           = “X-OTRS-TicketKey3”;          # TicketFreeKey
my $state_text          = “X-OTRS-TicketValue3”;        # TicketFreeText
my $host_state_name     = “Server-Status”;              # Value for TicketFreeKey (State of the Host)
my $service_state_name  = “Service-Status”;             # Value for TicketFreeKey (State of the Service)

# subjects
my $subject_close  = “NAGIOS: Problem ist behoben!”; # e.g. “Nagios: Problem solved”
my $subject_note = “NAGIOS: Problem besteht weiterhin!”; # e.g. “Nagios: Problem still exists”

# article type for notes
my $article_type  = ‘note-internal’; # note-internal|note-external|note-report

# from
my $from   = “NAGIOS”;

# end of configuration

my %Opts = ();
getopt(‘hSscaoNCT’, \%Opts);
my $HOST  = $Opts{‘h’};
my $SERVICE = $Opts{‘S’};
my $STATUS  = $Opts{‘s’};
my $CLOSE = $Opts{‘c’} || 0;
my $NT   = $Opts{‘N’} || “”;
my $AD   = $Opts{‘a’} || “”;
my $OUT  = $Opts{‘o’} || “”;
my $CONTACT  = $Opts{‘C’} || “”;
my $TYPE  = $Opts{‘T’};

if (!$HOST || !$SERVICE || !$STATUS || !$TYPE){
 print “\nAt least a HOST, SERVICE, TYPE and STATUS must be provided!\n”;
 exit(1);
}

# translate this if you like
my $MESSAGE =   “Art der Meldung: $NT\n”. # notificationtype
                “Service: $SERVICE\n”.  # service
                “Servername: $HOST ($AD)\n”. # host (address)
                “Status: $STATUS\n\n”.  # state
                “Ausgabe: $OUT”;  # output

my $statefield = $service_state_name;
if ($TYPE eq “h”){ $statefield = $host_state_name; }
my $ticketstate=””;
my $ticketsubject=””;
if ($CLOSE){
  $ticketstate = “closed successful”;
  $ticketsubject = $subject_close;
}else{
  $ticketstate = “open”;
  $ticketsubject = $subject_note;
}

#
# Create Job
#
my %Jobs = (
   ‘nagios_job’ => {
 # get all tickets with this properties
 Queue => \@nagios_queues,
 # Match Host
 TicketFreeText2 => $HOST,
 # Match Service
 TicketFreeText3 => $SERVICE,
 New => {
        Note => {
         From => $from,
         Subject => $ticketsubject,
         Body => $MESSAGE,
         ArticleType => $article_type,
        },
  # set new Service/Host-State
  TicketFreeKey4 => $statefield,
  TicketFreeText4 => $STATUS,
  # set new ticketstate
  State => $ticketstate,
 }
   }
);

#####
#
# THE FOLLOWING IS THE NON-CHANGED CODE OF GenericAgent.pl FROM OTRS V. 1.2.2
#
# If you like to use this script with other OTRS Versions maybe you have to
# replace the code
#
#####

# set generic agent uid
my $UserIDOfGenericAgent = 1;

# common objects
my %CommonObject = ();
$CommonObject{ConfigObject} = Kernel::Config->new();
$CommonObject{LogObject} = Kernel::System::Log->new(
    LogPrefix => ‘OTRS-GenericAgent’,
    %CommonObject,
);
$CommonObject{DBObject} = Kernel::System::DB->new(%CommonObject);
$CommonObject{TicketObject} = Kernel::System::Ticket->new(
    %CommonObject,
    Debug => $Debug,
);
$CommonObject{QueueObject} = Kernel::System::Queue->new(%CommonObject);

# —
# process all jobs
# —
foreach my $Job (sort keys %Jobs) {
    print “$Job:\n”;
    # —
    # get regular tickets
    # —
    my %Tickets = ();
    if (! $Jobs{$Job}->{Escalation}) {
        my %PartJobs = %{$Jobs{$Job}};
        if (!$PartJobs{Queue}) {
            print ” For all Queues: \n”;
            %Tickets = $CommonObject{TicketObject}->SearchTicket(
                %{$Jobs{$Job}},
                Limit => $Limit,
            );
        }
        elsif (ref($PartJobs{Queue}) eq ‘ARRAY’) {
            foreach (@{$PartJobs{Queue}}) {
                print ” For Queue: $_\n”;
                %Tickets = ($CommonObject{TicketObject}->SearchTicket(
                    %{$Jobs{$Job}},
                    Queues => [$_],
                    Limit => $Limit,
                ), %Tickets);
            }
        }
        else {
            %Tickets = $CommonObject{TicketObject}->SearchTicket(
                %{$Jobs{$Job}},
                Queues => [$PartJobs{Queue}],
                Limit => $Limit,
            );
        }
    }
    # —
    # escalation tickets
    # —
    else {
        if (! $Jobs{$Job}->{Queue}) {
            my @Tickets = $CommonObject{TicketObject}->GetOverTimeTickets();
            foreach (@Tickets) {
                $Tickets{$_} = $CommonObject{TicketObject}->GetTNOfId(ID => $_);
            }
        }
        else {
            my @Tickets = $CommonObject{TicketObject}->GetOverTimeTickets();
            foreach (@Tickets) {
                my %Ticket = $CommonObject{TicketObject}->GetTicket(TicketID => $_);
                if ($Ticket{Queue} eq $Jobs{$Job}->{Queue}) {
                    $Tickets{$_} = $Ticket{TicketNumber};
                }
            }
        }
    }
    # —
    # process each ticket
    # —
    foreach (sort keys %Tickets) {
        Run($Job, $_, $Tickets{$_});
    }
}
# —
# process each ticket
# —
sub Run {
    my $Job = shift;
    my $TicketID = shift;
    my $TicketNumber = shift;
    print “* $TicketNumber ($TicketID) \n”;
    # —
    # move ticket
    # —
    if ($Jobs{$Job}->{New}->{Queue}) {
        print ”  – Move Ticket to Queue ‘$Jobs{$Job}->{New}->{Queue}’\n”;
        $CommonObject{TicketObject}->MoveByTicketID(
            QueueID => $CommonObject{QueueObject}->QueueLookup(Queue=>$Jobs{$Job}->{New}->{Queue}, Cache => 1),
            UserID => $UserIDOfGenericAgent,
            TicketID => $TicketID,
        );
    }
    # —
    # add note if wanted
    # —
    if ($Jobs{$Job}->{New}->{Note}->{Body}) {
        print ”  – Add note\n”;
        $CommonObject{TicketObject}->CreateArticle(
            TicketID => $TicketID,
            ArticleType => $Jobs{$Job}->{New}->{Note}->{ArticleType} || ‘note-internal’,
            SenderType => ‘agent’,
            From => $Jobs{$Job}->{New}->{Note}->{From} || ‘GenericAgent’,
            Subject => $Jobs{$Job}->{New}->{Note}->{Subject} || ‘Note’,
            Body => $Jobs{$Job}->{New}->{Note}->{Body},
            UserID => $UserIDOfGenericAgent,
            HistoryType => ‘AddNote’,
            HistoryComment => ‘Note added.’,
        );
    }
    # —  
    # set new state
    # —
    if ($Jobs{$Job}->{New}->{State}) {
        print ”  – set state to ‘$Jobs{$Job}->{New}->{State}’\n”;
        $CommonObject{TicketObject}->SetState(
            TicketID => $TicketID,
            UserID => $UserIDOfGenericAgent,
            State => $Jobs{$Job}->{New}->{State},
        );
    }
    # —  
    # set customer id and customer user
    # —
    if ($Jobs{$Job}->{New}->{CustomerID} || $Jobs{$Job}->{New}->{CustomerUserLogin}) {
        if ($Jobs{$Job}->{New}->{CustomerID}) {
            print ”  – set customer id to ‘$Jobs{$Job}->{New}->{CustomerID}’\n”;
        }
        if ($Jobs{$Job}->{New}->{CustomerUserLogin}) {
            print ”  – set customer user id to ‘$Jobs{$Job}->{New}->{CustomerUserLogin}’\n”;
        }
        $CommonObject{TicketObject}->SetCustomerData(
            TicketID => $TicketID,
            No => $Jobs{$Job}->{New}->{CustomerID} || ”,
            User => $Jobs{$Job}->{New}->{CustomerUserLogin} || ”,
            UserID => $UserIDOfGenericAgent,
        );
    }
    # —  
    # set new priority
    # —
    if ($Jobs{$Job}->{New}->{Priority}) {
        print ”  – set priority to ‘$Jobs{$Job}->{New}->{Priority}’\n”;
        $CommonObject{TicketObject}->PrioritySet(
            TicketID => $TicketID,
            UserID => $UserIDOfGenericAgent,
            Priority => $Jobs{$Job}->{New}->{Priority},
        );
    }
    # —
    # set new owner
    # —
    if ($Jobs{$Job}->{New}->{Owner}) {
        print ”  – set owner to ‘$Jobs{$Job}->{New}->{Owner}’\n”;
        $CommonObject{TicketObject}->SetOwner(
            TicketID => $TicketID,
            UserID => $UserIDOfGenericAgent,
            NewUser => $Jobs{$Job}->{New}->{Owner},
        );
    }
    # —
    # set new lock
    # —
    if ($Jobs{$Job}->{New}->{Lock}) {
        print ”  – set lock to ‘$Jobs{$Job}->{New}->{Lock}’\n”;
        $CommonObject{TicketObject}->SetLock(
            TicketID => $TicketID,
            UserID => $UserIDOfGenericAgent,
            Lock => $Jobs{$Job}->{New}->{Lock},
        );
    }
    # —
    # set ticket free text options
    # —
    foreach (1..8) {
        if ($Jobs{$Job}->{New}->{“TicketFreeKey$_”} || $Jobs{$Job}->{New}->{“TicketFreeText$_”}) {
            my $Key = $Jobs{$Job}->{New}->{“TicketFreeKey$_”} || ”;
            my $Value = $Jobs{$Job}->{New}->{“TicketFreeText$_”} || ”;
            print ”  – set ticket free text to Key: ‘$Key’ Text: ‘$Value’\n”;
            $CommonObject{TicketObject}->SetTicketFreeText(
                TicketID => $TicketID,
                UserID => $UserIDOfGenericAgent,
                Key => $Key,
                Value => $Value,
                Counter => $_,
            );
        }
    }
    # —
    # run module
    # —
    if ($Jobs{$Job}->{New}->{Module}) {
        print ”  – use module ($Jobs{$Job}->{New}->{Module})\n”;
        $CommonObject{LogObject}->Log(
            Priority => ‘notice’,
            Message => “Use module ($Jobs{$Job}->{New}->{Module}) Ticket [$TicketNumber], TicketID [$TicketID].”,
        );
        if ($Debug) {
            $CommonObject{LogObject}->Log(
                Priority => ‘debug’,
                Message => “Try to load module: $Jobs{$Job}->{New}->{Module}!”,
            );
        }
        if (eval “require $Jobs{$Job}->{New}->{Module}”) {
            my $Object = $Jobs{$Job}->{New}->{Module}->new(
                %CommonObject,
                Debug => $Debug,
            );
            if ($Debug) {
                $CommonObject{LogObject}->Log(
                    Priority => ‘debug’,
                    Message => “Loaded module: $Jobs{$Job}->{New}->{Module}!”,
                );
                $CommonObject{LogObject}->Log(
                    Priority => ‘debug’,
                    Message => “Run module: $Jobs{$Job}->{New}->{Module}!”,
                );
            }
            $Object->Run(TicketID => $TicketID);
        }
        else {
            $CommonObject{LogObject}->Log(
                Priority => ‘error’,
                Message => “Can’t load module: $Jobs{$Job}->{New}->{Module}!”,
            );
        }
    }
    # —
    # cmd
    # —
    if ($Jobs{$Job}->{New}->{CMD}) {
        print ”  – call cmd ($Jobs{$Job}->{New}->{CMD}) for ticket_id $_\n”;
        $CommonObject{LogObject}->Log(
            Priority => ‘notice’,
            Message => “Execut ‘$Jobs{$Job}->{New}->{CMD} $TicketNumber $TicketID’.”,
        );
        system(“$Jobs{$Job}->{New}->{CMD} $TicketNumber $TicketID “);
    }
    # —
    # delete ticket
    # —
    if ($Jobs{$Job}->{New}->{Delete}) {
        print ”  – delete ticket_id $TicketID\n”;
        $CommonObject{LogObject}->Log(
            Priority => ‘notice’,
            Message => “Delete Ticket [$TicketNumber], TicketID [$TicketID].”,
        );
        $CommonObject{TicketObject}->DeleteTicket(
            UserID => $UserIDOfGenericAgent,
            TicketID => $TicketID,
        );
    }
}
# —

 

@
@@@@

@@@@@@

@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@

 

 

2)))))  Attachment (otrs_ticket_handler.pl):

 

@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@

 

 
#!/usr/bin/perl

use strict;
use Mail::Send;
use Getopt::Std;

# configuration

# Email of the OTRS-system
my $emailto   = “otrs\@my-company.xyz”;
# standard Queue (if no contact alias available from nagios)
my $std_queue   = “nagios_test”;
#
# Definitions for TicketFreeKeys and TicketFreeText
# (use the same settings in NagiosGenericAgent.pl !!)
# definitions for host freefield
my $host_key   = “X-OTRS-TicketKey2”;  # TicketFreeKey
my $host_text   = “X-OTRS-TicketValue2”; # TicketFreeText
my $host_name  = “Server”;   # Value for TicketFreeKey
# definitions for service freefield
my $service_key  = “X-OTRS-TicketKey4”;  # TicketFreeKey
my $service_text  = “X-OTRS-TicketValue4”; # TicketFreeText
my $service_name = “Service”;   # Value for TicketFreeKey
# definitions for state freefield
my $state_key   = “X-OTRS-TicketKey3”;  # TicketFreeKey
my $state_text   = “X-OTRS-TicketValue3”; # TicketFreeText
my $host_state_name = “Server-Status”;  # Value for TicketFreeKey (State of the Host)
my $service_state_name = “Service-Status”;  # Value for TicketFreeKey (State of the Service)
 
# script execution command for closing tickets and adding notes
#
# nagios user (e.g. daemon) needs to execute this command without
# having to type a password. Create an ssh key pair and place the
# public key in .ssh/authorized_key of the otrs user.
#
my $ga_script = “ssh otrs\@otrs-host /opt/otrs/bin/NagiosGenericAgent.pl”;

# end of configuration

my $MAIL = 1;
my $ADD_NOTE = 2;
my $CLOSE = 3;
my $action;

# Read Commandline Options
my %Opts = ();
getopt(‘HSsNdaonCT’, \%Opts);

if (!$Opts{“H”} || !$Opts{“S”} || !$Opts{“s”} || !$Opts{“T”} || !( $Opts{“T”} eq ‘s’ || $Opts{“T”} eq ‘h’ )){
 print “Usage: otrs_mail.pl -T [s,h] -H HOSTALIAS -S SERVICEDESCRIPTION -s STATE \n”.
  ”      [ -t DATETIME -n NOTIFICATIONNUMBER -a HOSTADRESS -o OUTPUT \n”.
  ”  -N NOTIFICATIONTYPE -C CONTACTALIAS]\n”;
 exit(1);
}

# get Service State and set action
if ($Opts{‘N’} eq “PROBLEM” && $Opts{‘n’} == 1){
 $action = $MAIL;     
}elsif ($Opts{‘N’} eq “RECOVERY”){
 $action = $CLOSE;
}elsif ($Opts{‘N’} eq “PROBLEM” || $Opts{‘N’} eq “ACKNOWLEDGEMENT”){
 $action = $ADD_NOTE;
}

# set variables for HOST-Notification
my $type = ” -T h”;
my $freefield =$host_state_name;
my $subject = “Nagios-alert: HOST $Opts{‘H’} IS DOWN!!!”;
if ($Opts{‘T’} eq “s”){
 # set variables for SERVICE-Notification
 $type = ” -T s”;
 $freefield = $service_state_name;
  $subject = “Nagios-alert: Service-Check ‘$Opts{‘S’}’ hat den Status ‘$Opts{‘s’}’ auf Server ‘$Opts{‘H’}'”;
}

my $message =   “Art der Meldung: $Opts{‘N’}\n”.
                “Service: $Opts{‘S’}\n”.
                “Servername: $Opts{‘H’}\n”.
                “Serveradresse: $Opts{‘a’}\n”.
                “Status: $Opts{‘s’}\n\n”.
                “Ausgabe: $Opts{‘o’}”;

my $sshcmd =  $ga_script . ” -h $Opts{‘H’} -S $Opts{‘S’} -s $Opts{‘s’} “.
       “-N $Opts{‘N’} -a \”‘$Opts{‘a’}’\” -C $Opts{‘C’} \”‘-o $Opts{‘o’}’\””;

# send email to OTRS = Create new Ticket
if ($action eq $MAIL){
 # OTRS-Email

 my $msg = new Mail::Send;
 $msg->to($emailto);
 $msg->subject($subject);

 # set headers so that message is put in the correct queue
 # and TicketFreeText fields are filled
 my $queue = $Opts{‘C’} || $std_queue;
 $msg->set(“X-OTRS-Queue”, $queue);
 $msg->set($host_key, “Host”);
 $msg->add($host_text,$Opts{“H”} );
 $msg->set($service_key, “Service”);
 $msg->add($service_text,$Opts{“S”} );
 $msg->set($state_key, $freefield);
 $msg->add($state_text, $Opts{“s”} );

 my $fh = $msg->open;               # some default mailer
 print $fh $message; 

 $fh->close;              # complete the message and send it
}elsif ($action eq $CLOSE){
        #
        # CLOSE TICKET ON OTRS SYSTEM
        #
        my $cmd = $sshcmd . ” -c 1″ . $type;
        system($cmd);

}elsif ($action eq $ADD_NOTE){
 #
 # ADD TICKET NOTE ON OTRS SYSTEM
 #
        my $cmd = $sshcmd . ” -c 0″ . $type ;
 system($cmd);
}

 

 

 

Categories: Linux, nagois, otrs, tutorial


Sample

Xen Virtualization on Linux and Solaris

RH’s opensource distros ISO images (Fedora,CentOS) have a nice feature,been loop mounted on apache folder /var/www/domain, they allow to create local mirror to virt-install corresponding paravirtual guest. Not customized Ubuntu ISOs don’t have this feature, however virt-install still works for Oneiric, Natty, Lucid utilizing remote system HTTP source. Virt-install Oneiric PV DomU is possible via remote official HTTP source :-
http://ca.archive.ubuntu.com/ubuntu/dists/oneiric/main/installer-amd64/.
Start install by command :-

virt-install --connect xen:/// -n OneiricPV \
--nographics \
-p -r 2048 --vcpus=2 -f /dev/sdb6 \
-l http://ca.archive.ubuntu.com/ubuntu/dists/oneiric/main/installer-amd64/

proceed with text mode install









Diring tasksel run I’ve selected “Basic Ubuntu Server”,”SSH”,”Ubuntu Desktop”



all done domain reboots



Open Virt-Manager and add VNC Server to graphics section



Start updated DomU via Virt-Manager:-




View original post

Categories: Uncategorized


Sanjupommen's Blog

This post describes how to automate System Monitoring with OTRS and Nagios.

OTRS is an Open source Ticket Request used to manage customer telephone calls and e-mails. The system
supports network service, sales, pre-sales, internal IT, helpdesk etc. department to react quickly to inquiries.
Nagios is a system and network monitoring system that can be used to monitor many network services like
SMTP, HTTP etc… on remote hosts. It alerts the recipient groups when any system goes down or malfunctions.

OTRS is an Open source Ticket Request used to manage customer telephone calls and e-mails. The systemsupports network service, sales, pre-sales, internal IT, helpdesk etc. department to react quickly to inquiries.Nagios is a system and network monitoring system that can be used to monitor many network services likeSMTP, HTTP etc… on remote hosts. It alerts the recipient groups when any system goes down or malfunctions.

Requirements

  1. Running Instance of OTRS.

View original post 629 more words

Categories: Uncategorized

Applications failing with /etc/mtab errror


Check on

cat /proc/mounts and ensure all mounts  listed in /etc/fstab are mounted

For those NOT mounted  mount with mount command

If  possible a reboot at times  solve the problem.

Linux based file systems become read-only


VMware has identified a problem where file systems may become read-only after encountering busy I/O retry or SAN or iSCSI path

failover errors.
 
The same behavior is expected even on a native Linux environment, where the time required for the file system to become read-only

depends on the number of paths available to a particular target, the multi-path software installed on the operating system, and

whether the failing I/O was to an EXT3 Journal. However, the problem is aggravated in an ESX host environment because ESX host

manages multiple paths to the storage target and provides a single path to the guest operating system, which effectively reduces the

number of retries done by the guest operating system.
 
These guest operating systems are affected:
•RHEL5 (RedHat)
•RHEL4 U6
•RHEL4 U4
•RHEL4 U3
•SLES10
•SLES9 SP3
•Ubuntu 7.04 

Note: This issue may affect other Linux distributions based on early 2.6 kernels as well, such as Ubuntu 7.04.
Solution
Note: This article does not supersede the Guest Operating System Installation Guide. A guest operating system upgrade may require an

ESX upgrade as well.
 
This Linux kernel bug has been fixed in different updates of different Linux distributions. Not all kernel versions include the

patch. Contact your Linux Distributor for more information.
•For RHEL5, upgrade to Update 1 (also referred to as RHEL5.1). For more information, see the RedHat Bug 228108.
•For RHEL4 U6, upgrade to kernel version 2.6.9-89.0.7. For more information, see the RedHat Bug 197158.
•For RHEL4 U3 and RHEL U4, upgrade to Update 5 (RHEL 4.5).
•For SLES10, upgrade to SP2. For more information, see the Novell Knowledge Base article 3605538.
•For SLES9 SP3, upgrade to SP4 or SP3 Maintenance Release build 2.6.5-7.286. For more information, see the Novell Knowledge Base

article 7005154.
•For Ubuntu 7.04, upgrade to 7.10.
Additional Information
As a workaround, remount the Linux file system using this command to return it to the proper state:
 
mount -o remount /
 
Note: It is ideal to identify the problem and resolve the issue rather than performing this workaround when this situation arises.
 
For translated versions of this article, see

See link:

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=51306

 

Xen Virtualization guide


Xen Virtualization guide

Xen Tutorial on installing Xen

Categories: Uncategorized

Wireless USB adapter doesn’t work on Ubuntu.


What you will need
– Your Ubuntu installation CD
– Your windows drivers/hardware drivers cd or download from internet

The solution

You will need to get a few programs running to get your adater working. One is a program which I think controls and ‘helps’ wireless networking run and the second is a graphical user interface which converses with the first program without the user having to use the command line. Follow these steps

Go to: System > Administration > Synaptic Package Manager
Search there for: ndiswrapper-utils, ndiswrapper-common and ndisgtk
If nothing is found then Insert your Ubuntu CD
You will now need to add the CD to your ‘Souces’. In administration ‘Manage Sources’ and add your cd/dvd
Now in Synaptic Package Manager click on “Source” (This means the Ubuntu Source CD I think!?)
Again search for ndiswrapper-utils, ndiswrapper-common and ndisgtk
You should now be able to tick these items and save the Package Manager, which will then install the three programs
Go to System > Administration > Windows Wireless devices (This is the new program you’ve just installed ndiskgt thanks to Sam Pohlenz)
Now Click on Insert New Driver
Insert your cd which came with your wireless device
Browse to the cd and look for the .inf files.
Select the .inf file
Note: Normally these will be in a config forlder or an inf folder and will probably be oranised by Windows Operating System. I chose Windows 7 driver as this was most recent but with one adapter this didn’t work. I think it will probably be a case of ‘if at first you don’t succeed’
Install

Voila, you should see an icon appear next to your volume control which is your Network Manager. This will allow you to select a Network, and tweak your wireless settings.

If you are at this stage and still Ubuntu des not see your wireless USB it is time to either try another driver, or look for alternative solutions.
I could now see the wireless Networks but still could not connect?

source;

How to install wireless USB drivers for Ubuntu

Categories: Uncategorized

delete files older than x days linux


find /path/to/files* -mtime +x -exec rm {} \;

/path/to/files*

this is the path to where the files are located

-mtime

used to specify the number of days old ,  for example -mtime +10 for older than 10days

-exec

allows you to pass in a command eg  rm

{}\;

need that to end the command

 

 

Invalid command ‘PythonHandler’, perhaps misspelled or defined by a module


Invalid command ‘PythonHandler’, perhaps misspelled or defined by a module…

I have had apache working well all this while on ubuntu then after installing smce security updates and restarting the server, I realised that the apache2 service didn’t start because no web pages were being served even though the server was up.  I tried to restart the apache2 web service and got this error message “Invalid command ‘PythonHandler’, perhaps misspelled or defined by a module …”

I realized that the following module “libapache2-mod-python” was not installed so i did a

1)sudo apt-get install libapache2-mod-python

and then

2)a2enmod python

doing a tail -f /var/log/apache2/error.log I  get this

[Wed Aug 10 09:16:21 2011] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Wed Aug 10 09:16:21 2011] [notice] mod_python: using mutex_directory /tmp
[Wed Aug 10 09:16:22 2011] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.9 with Suhosin-Patch mod_python/3.3.1 Python/2.6.5 configured — resuming normal operation

I ran the command sudo service apache2 restart and the apache service started successfully and the server started serving pages just like before.

The server has always started with no issues but since I am working on this sever with other people, i will only assume that someone may have done something that interfered with the normal working process of the server.

Windows 2008 drive C


Your drive C on Windows 2008 space is disappearing and you don’t seem to see the files eating up that space.

It is likely  hibernation is turned on and in most cases you don’t need.

Disable it and you will see a change space usage. Actually disabling it removes hiberfil.sys file

To make hibernation unavailable, follow these steps:

  1. Click Start, and then type cmd in the Start Search box.
  2. In the search results list, right-click Command Prompt, and then click Run as Administrator.
  3. When you are prompted by User Account Control, click Continue.
  4. At the command prompt, type powercfg.exe /hibernate off, and then press ENTER.
  5. Type exit and then press ENTER to close the Command Prompt window.

To make hibernation available, follow these steps:

  1. Click Start, and then type cmd in the Start Search box.
  2. In the search results list, right-click Command Prompt, and then click Run as Administrator.
  3. When you are prompted by User Account Control, click Continue.
  4. At the command prompt, type powercfg.exe /hibernate on, and then press ENTER.
  5. Type exit and then press ENTER to close the Command Prompt window.