SendNagiosAlert: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 7: Line 7:
Custom Condition:
Custom Condition:


     if ($self->TransactionObj->Type eq 'Create' ||
     if ($self->TransactionObj->Type eq 'Create' ||
             $self->TransactionObj->Type eq 'Status' ||
             $self->TransactionObj->Type eq 'Status' ||
             ($self->TransactionObj->Type eq 'Set' && $self->TransactionObj->Field eq "Queue"))  {
             ($self->TransactionObj->Type eq 'Set' && $self->TransactionObj->Field eq "Queue"))  {
         return(1);
         return(1);
     } else {
     } else {
         return(undef);
         return(undef);
     }
     }


Action: User Defined
Action: User Defined
Line 31: Line 30:
       my $nscaBin = '/usr/local/nagios/libexec/send_nsca';
       my $nscaBin = '/usr/local/nagios/libexec/send_nsca';
       my $nscaCfg = '/usr/local/nagios/etc/send_nsca.cfg';
       my $nscaCfg = '/usr/local/nagios/etc/send_nsca.cfg';
       my $nscaHst = '<IP of nagios server>';
       my $nscaHst = '<IP of nagios server>';
 
       foreach my $QueueName (keys %hosts) {
       foreach my $QueueName (keys %hosts) {
         my $hostname = $hosts{$QueueName};
         my $hostname = $hosts{$QueueName};
         my $TicketsObj = RT::Tickets-&gt;new($RT::SystemUser);
         my $TicketsObj = RT::Tickets->new($RT::SystemUser);
         $TicketsObj-&gt;LimitStatus(VALUE =&gt; 'open');
         $TicketsObj->LimitStatus(VALUE => 'open');
         $TicketsObj-&gt;LimitStatus(VALUE =&gt; 'new');
         $TicketsObj->LimitStatus(VALUE => 'new');
         $TicketsObj-&gt;LimitQueue(VALUE =&gt; $QueueName);
         $TicketsObj->LimitQueue(VALUE => $QueueName);
         my $count = $TicketsObj-&gt;Count();
         my $count = $TicketsObj->Count();
         if ($count eq '0') {
         if ($count eq '0') {
           system("printf \"$hostname\\t$QueueName\\t0\\t$QueueName: No Alerts\\n\" | $nscaBin -H $nscaHst -c $nscaCfg");
           system("printf \"$hostname\\t$QueueName\\t0\\t$QueueName: No Alerts\\n\" | $nscaBin -H $nscaHst -c $nscaCfg");
Line 48: Line 47:
       1;
       1;
     }
     }





Latest revision as of 17:40, 8 January 2017

Here's a Scrip that you can use to send an alert to Nagios if a ticket is new or open in a particular Queue(s). This scrip will only run if a ticket is created, a ticket's status is changed, or a ticket is moved to another queue. If one of these conditions is met, then it will looked at each queue defined in the scrip to see if there are any open or new Tickets in those queues. If there are no tickets in that queue, it will send an OK to the corresponding nagios service. If there are new or open tickets in that queue, it will send a CRITICAL to the corresponding nagios alert.

You must have Nagios already configured for this passive check, have send_nsca installed on the RT server, and the nsca [p_view=140 http://www.nagiosexchange.org/Communication.41.0.html?&tx_netnagext_pi1[p_view]=140] daemon running on the Nagios server.

Condition: User Defined

Custom Condition:

   if ($self->TransactionObj->Type eq 'Create' ||
           $self->TransactionObj->Type eq 'Status' ||
           ($self->TransactionObj->Type eq 'Set' && $self->TransactionObj->Field eq "Queue"))  {
       return(1);
   } else {
       return(undef);
   }

Action: User Defined

Custom action preparation code:

   1;

Custom action cleanup code:

   {
     my %hosts = qw(
         Queue-Name1      definedNagiosHost1.domain.com
         Queue-Name2      definedNagiosHost2.domain.com
     );
     my $nscaBin = '/usr/local/nagios/libexec/send_nsca';
     my $nscaCfg = '/usr/local/nagios/etc/send_nsca.cfg';
     my $nscaHst = '<IP of nagios server>';
     foreach my $QueueName (keys %hosts) {
       my $hostname = $hosts{$QueueName};
       my $TicketsObj = RT::Tickets->new($RT::SystemUser);
       $TicketsObj->LimitStatus(VALUE => 'open');
       $TicketsObj->LimitStatus(VALUE => 'new');
       $TicketsObj->LimitQueue(VALUE => $QueueName);
       my $count = $TicketsObj->Count();
       if ($count eq '0') {
         system("printf \"$hostname\\t$QueueName\\t0\\t$QueueName: No Alerts\\n\" | $nscaBin -H $nscaHst -c $nscaCfg");
       } else {
         system("printf \"$hostname\\t$QueueName\\t2\\t$QueueName: Open Alert(s)\\n\" | $nscaBin -H $nscaHst -c $nscaCfg");
       }
     }
     1;
   }


Template: Global Template: Blank

See also: ManualScrips, WriteCustomAction, WriteCustomCondition