Ad Widget

Collapse

Having proble with remote command in PHP.Have anybody met that?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • admin5795@gmail.com
    Junior Member
    • Aug 2012
    • 7

    #1

    Having proble with remote command in PHP.Have anybody met that?

    In order to provide flexible notification messages,I use php script as remote command to send notification email.However,I've found some problem as follow.

    At first ,the script is usable,I can receive email as defined upon event.Then,for example,I'd like the email contains command top's output.I use following command:
    $mailbody = shell_exec("top -n 1");
    The above is one of the main code in my script,in order to get top's output.

    If I run the script by hand in command,then I can get top's output in the email.But if I run it through zabbix frontend, the email I received just with an empty content.It seemed that $mailbody = shell_exec("top -n 1") wasn't parsed properly.

    After that,I do followings
    I replace the "top" with absolute path that is "/usr/bin/top" or command non-exist,I find the status of the action is ok in the frontend,But also have empty message.

    I also gussed that maybe user zabbix with a shell "/sbin/nologin" causes the problem,then I changed its shell to /bin/bash and create it home dir,but that have no effect.

    I refer to the log file, but found nothing.

    Can anybody give me some advice?
  • admin5795@gmail.com
    Junior Member
    • Aug 2012
    • 7

    #2
    addtional message

    Click image for larger version

Name:	`VZ${P3LD3H[Y{}0`[AI0ND.jpg
Views:	1
Size:	83.8 KB
ID:	311906
    Above is my action’s config.
    I'm also confused about “Target list” and “Execute on” as the document doesn't give exact explanation.

    Comment

    • admin5795@gmail.com
      Junior Member
      • Aug 2012
      • 7

      #3
      addtional message

      [root@314360 abc]# cat alert_script.php
      #!/bin/php
      <?php

      for ($i = 1;$i < $argc;$i++) {
      list( ,$value[$i]) = split("=",$argv[$i]);
      }

      $host = $value[1];
      $ip = $value[2];
      $issue = $value[3];
      $triggerid = $value[4];
      $eventid = $value[5];
      $itemid = $value[6];

      $mailsubject = $issue;
      $mailbody = shell_exec("top -n 1");

      include_once("warning.php");

      ?>
      warning.php is a file used to send warning level mssage.
      Last edited by [email protected]; 24-08-2012, 03:38. Reason: copy wrong

      Comment

      • sirtech
        Junior Member
        • Aug 2012
        • 25

        #4
        Try running top in batch mode

        Might be something to do with where top is sending the output which you wouldn't notice in a terminal because it "appears on screen" anyway. Try running top in batch mode as the exec command:

        Code:
        top -b n1
        Also it is a good idea to continue use the full path to top on that host whilst trying to find the problem.

        Comment

        • admin5795@gmail.com
          Junior Member
          • Aug 2012
          • 7

          #5
          thanks

          Originally posted by sirtech
          Might be something to do with where top is sending the output which you wouldn't notice in a terminal because it "appears on screen" anyway. Try running top in batch mode as the exec command:

          Code:
          top -b n1
          Also it is a good idea to continue use the full path to top on that host whilst trying to find the problem.
          great,that's it.Thank you very much

          Comment

          Working...