Ad Widget

Collapse

Sending mail when trigger is on for x minute

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeXTeR-ITA
    Junior Member
    • Dec 2007
    • 22

    #1

    Sending mail when trigger is on for x minute

    Hi all,
    this is my first post, but I read the forum from few month and I find help for any problem that I have.

    I have to do one more thing, I want to receive an email when a trigger, for a running process, is "on" for a 1 hour.

    I try this expression:
    Code:
    {Template_CF-Linux-Server-virtual1:proc.num[activedvddaemon].min(3600)}<1
    but the trigger go on immediately when the process go down, and the mail is sent. This process go up and down many times per day.

    Can someone help me?
    Thank you all!

    Zabbix ver. 1.4.1
  • cristhiano
    Member
    • Nov 2007
    • 48

    #2
    Would be good if there was a expression to get lastchange value of triggers table.

    Comment

    • johnnyirons
      Junior Member
      • Dec 2007
      • 16

      #3
      this is a sample of code i use on my own.
      i have this up to notice me if a trigger is on for an hour, and no one has take this in charge; in this case, we send a mail to a ticket system to escalate the problem.
      a note: as you may see, i put into consideration only triggers with a prio at least high, and that have not been acked.
      Our team send a mail (with the template below), but you could do anything you want with it, eg. exec() a script, or such.

      Code:
      <?php
      
      require_once "include/config.inc.php";
      
      // against zabbix >= 1.4.2 
      
      $ZABBIX_SERVER_URI = "http://zabbixserver";
      
      // define how old a trigger must be before warning (in seconds)
      $timelapse = 3600;
       
      // sort out triggers, severity >= high, and not acknowleged
      $result = DBselect("select distinct t.triggerid,t.status,t.description,t.expression,t.priority,t.lastchange,t.comments,t.url,t.value,h.host,e.objectid,
       e.object,e.acknowledged,i.lastvalue from triggers t,hosts h,items i,functions f,events e where f.itemid=i.itemid and h.hostid=i.hostid 
       and t.triggerid=f.triggerid and t.triggerid=e.objectid and e.object=0 and t.status=0 and i.status=0 and h.status=0 and e.acknowledged=0 
       and t.priority>=3 and t.value=1 and (".time()." - lastchange) > ".$timelapse." order by t.lastchange desc, t.priority");
       
      while($row=DBfetch($result))
      {
      		// check if is a dependency
      		$deps = DBfetch(DBselect("select count(*) as cnt from trigger_depends d, triggers t ".
      				" where d.triggerid_down=".$row["triggerid"]." and d.triggerid_up=t.triggerid and t.value=1"));
      
      		if($deps["cnt"]>0)
      		{
      				continue;
      		}
      		
      		// template mail generation
      		// vars: $row["host"] $row["description"] $row["lastvalue"] 
      		$difference=time() - $row["lastchange"];
      		echo "\nHost: ".$row["host"]." Trigger: ".$row["description"]." - last value: ".$row["lastvalue"]."\n";
      		echo " alarm active since: ";
      		echo floor($difference / 86400);
      		$difference -= 86400 * floor($difference / 86400);
      		echo " days, ";
      		echo floor($difference / 3600);
      		$difference -= 3600 * floor($difference / 3600);
      		echo " hours, ";
      		echo floor($difference / 60);
      		$difference -= 60 * floor($difference / 60);
      		echo " minutes, and $difference seconds ago.\n";
      		
      		/* Do your stuff here - eg. open a ticket (if tihs has not been put in charge by anyone),
      		*  send mail, fire an sms, etc. */
      		
      		/*
      		$sendmail_from = "[email protected]";
      		$to = "[email protected]";
      		$subject = "Zabbix alarm: [".$row["host"]." - ".$row["description"]."]";
      		$msg = "Hello. This is Zabbix @ NOC\n\nThe following alarm has not been acknowledged by anyone in ".$timelapse." seconds:\n";
      		$msg .= "--------------------\nHostname: ".$row["host"]."\nAlarm: ".$row["description"]."\n--------------------\n\n";
      		$msg .= "Please go to ".$ZABBIX_SERVER_URI."/tr_events.php?triggerid=".$row["triggerid"]."\n\nSincerely,\n  NOC team.\n";
      		$headers = "From: ".$sendmail_from."\r\nReply-To: ".$sendmail_from."\r\n";
      		$config = "-f".$sendmail_from;
      		if (!mail("$to", "$subject", "$msg", "$headers", "$config")) {
      			echo "Problem sending mail!!";
      		} else {
      			echo " Mail sent.\n";
      		}
      		*/
      	}
      
      ?>

      hope you find it useful.

      G.

      Comment

      • cstackpole
        Senior Member
        Zabbix Certified Specialist
        • Oct 2006
        • 225

        #4
        First, Welcome to Zabbix!
        Second try this:

        {Template_CF-Linux-Server-virtual1: proc.num[activedvddaemon].avg(3600)}=1
        (remove the space between": p" if you plan on copy/pasting)

        There might be a better way of doing this, but this has worked for me.
        Good luck!

        cstackpole

        Comment

        • johnnyirons
          Junior Member
          • Dec 2007
          • 16

          #5
          Originally posted by cstackpole
          First, Welcome to Zabbix!
          Second try this:

          {Template_CF-Linux-Server-virtual1: proc.num[activedvddaemon].avg(3600)}=1
          (remove the space between": p" if you plan on copy/pasting)

          There might be a better way of doing this, but this has worked for me.
          Good luck!

          cstackpole
          i tried this, but it has a big disadvantage for me: it closes and reopen the trigger.
          since i use the trigger events for SLA (to customers) and for ticket management (internally in the NOC, using acknowlegements), i don't want to change trigger state, just the notification.

          Comment

          • DeXTeR-ITA
            Junior Member
            • Dec 2007
            • 22

            #6
            I tried different configurations, I found what works for me, simply:

            Code:
            {Template_CF-Linux-Server-virtual1:proc.num[activedvddaemon].max(3600)}<1
            Thank's!

            Alessandro

            Comment

            Working...