Ad Widget

Collapse

Fix for linked triggers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • linuxdr
    Junior Member
    • Jun 2005
    • 12

    #1

    Fix for linked triggers

    I am using Alpha10 and had a problem with Linked triggers. I found that when I had an expression like:

    ({Racksaver.Linux:http.last(0)}=1)&({Racksaver.Lin ux:http.time(0)}>061500)&({Racksaver.Linux:http.ti me(0)}<054500)

    in my template that only the first expression was changed to the new host and came out like:

    ({Blade01:http.last(0)}=1)&({Racksaver.Linux:http. time(0)}>061500)&({Racksaver.Linux:http.time(0)}<0 54500)

    This caused a lot of problems. I was able to fix this by adding the following line into the function add_trigger_to_templates():

    $trigger["expression"] = $expression;

    It was on line 388 in triggers.inc.php. Here are the lines surrounding it to help:

    $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$tri$
    DBexecute($sql);
    $expression=str_replace("{".$row2["functionid"]."}","{".$functionid."}",$trigger["expr$
    $trigger["expression"] = $expression;
    $sql="update triggers set expression='$expression' where triggerid=$triggerid_new";
    DBexecute($sql);

    This seemed to fix the problem.
  • linuxdr
    Junior Member
    • Jun 2005
    • 12

    #2
    Didn't fix the problem

    Well, this didn't fix the problem. Not sure how I missed it but it then changed every entry to the first host in the linked templates so that all blades say blade01 for everything. Back to the drawing board.

    Comment

    • linuxdr
      Junior Member
      • Jun 2005
      • 12

      #3
      Finally Got It

      Here is the new function code:

      function add_trigger_to_templates($triggerid)
      {
      if($triggerid<=0)
      {
      return;
      }

      $trigger=get_trigger_by_triggerid($triggerid);

      $sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=$triggerid";
      $result=DBselect($sql);
      if(DBnum_rows($result)!=1)
      {
      return;
      }

      $row=DBfetch($result);

      $hostid=$row["hostid"];

      $sql="select hostid,templateid,items from hosts_templates where templateid=$hostid";
      $result=DBselect($sql);
      while($row=DBfetch($result))
      {
      if($row["triggers"]&1 == 0) continue;

      $sql="insert into triggers (description,priority,status,comments,url,value,ex pression) values ('".addslashes($trigger["description"])."',".$trigger["priority"].",".$trigger["status"].",'".addslashes($trigger["comments"])."','".addslashes($trigger["url"])."',2,'".$trigger["expression"]."')";
      $result4=DBexecute($sql);
      $triggerid_new=DBinsert_id($result4,"triggers","tr iggerid");


      $sql="select i.key_,f.parameter,f.function,f.functionid from functions f,items i where i.itemid=f.itemid and f.triggerid=$triggerid";
      $result2=DBselect($sql);

      $time_temp = 1;
      while($row2=DBfetch($result2))
      {
      $sql="select itemid from items where key_=\"".$row2["key_"]."\" and hostid=".$row["hostid"];
      $result3=DBselect($sql);
      if(DBnum_rows($result3)!=1)
      {
      $sql="delete from triggers where triggerid=$triggerid_new";
      DBexecute($sql);
      $sql="delete from functions where triggerid=$triggerid_new";
      DBexecute($sql);
      break;
      }
      $row3=DBfetch($result3);

      $item=get_item_by_itemid($row3["itemid"]);

      $sql="insert into functions (itemid,triggerid,function,parameter) values (".$item["itemid"].",$triggerid_new,'".$row2["function"]."','".$row2["parameter"]."')";
      $result4=DBexecute($sql);
      $functionid=DBinsert_id($result4,"functions","func tionid");

      $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid_new";
      DBexecute($sql);
      if( $time_temp == 1 )
      $expression=str_replace("{".$row2["functionid"]."}","{".$functionid."}",$trigger["expression"]);
      else
      $expression=str_replace("{".$row2["functionid"]."}","{".$functionid."}",$expression);

      $sql="update triggers set expression='$expression' where triggerid=$triggerid_new";
      DBexecute($sql);

      $host=get_host_by_hostid($row["hostid"]);
      info("Added trigger to linked host ".$host["host"]);
      $time_temp++;
      }
      }
      }

      Had to add a loop with $time_temp. This seems to have fixed the problem.

      Comment

      Working...