HELP! Huge script_serv.php bug or I'm doing something wrong?

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
User avatar
Alice
Cacti User
Posts: 111
Joined: Tue Oct 28, 2003 4:54 pm
Location: Bucharest, RO.

HELP! Huge script_serv.php bug or I'm doing something wrong?

Post by Alice »

root@Zombie:/x/cacti# php script_server.php
PHP Script Server has Started - Parent is cmd
/x/cacti/scripts/ss_valute.php ss_valute get live EUR
/x/cacti/scripts/ss_dobanzi.php ss_dobanzi get valoare LIBOREUR6M
4.24
U
1.6088
U
ipts/ss_valute.php ss_valute get live EUR
4.24
U
nzi.php ss_dobanzi get valoare LIBOREUR6M
1.6088
U
mnzi.php ss_dobanzi get valoare LIBOREUR6M
1.6088
U
this should return an error nzi.php ss_dobanzi get valoare LIBOREUR6M
WARNING: Function does not exist
mnzi.php ss_dobanzi get valoare LIBOREUR6M
1.6088
U
this-should-return-an-error-too-php ss_dobanzi get valoare LIBOREUR6M
1.6088
U
OK, so what's wrong? :(

Latest cacti version, of course.
My problem is that values seem to get 'mixed'
Last edited by Alice on Thu Apr 23, 2009 1:53 am, edited 2 times in total.
[url=http://www.x-graphs.com/]http://www.x-graphs.com[/url] [color=red]X[/color]-[color=blue]graphs[/color] :: All kind of graphs
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

1) Have you read in the documentation site how to create scripts?
2) My psychic powers are lacking this morning, I can't picture the contents of that ss_ script...
User avatar
Alice
Cacti User
Posts: 111
Joined: Tue Oct 28, 2003 4:54 pm
Location: Bucharest, RO.

Post by Alice »

1) Yep... I also made some scripts that work absolutely fine, on another server.
2) Sorry :D

Code: Select all

<?php

/* do NOT run this script through a web browser */
if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD'])  || isset($_SERVER['REMOTE_ADDR'])) {
   die("<br><strong>This script is only meant to run at the command line.</strong>");
}

$no_http_headers = true;
/* display No errors */
error_reporting(0);

include_once(dirname(__FILE__) . "/../lib/snmp.php");

if (!isset($called_by_script_server)) {
        include_once(dirname(__FILE__) . "/../include/global.php");
        array_shift($_SERVER["argv"]);
        print call_user_func_array("ss_valute", $_SERVER["argv"]);
}

function ss_valute($cmd, $arg1 = "", $arg2 = "") {
include "db.php";

        if ($cmd == "index") {

            $query="select * from curs";
            $result = mysql_query($query);
            while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {;
                print $row['Valuta']."\n";
            }

        }elseif ($cmd == "query") {
            $arg = $arg1;
            $query="select * from curs";
            $result = mysql_query($query);

            if ($arg=="valuta")
            while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {;
                print $row['Valuta']."!".$row['Valuta']."\n";
                exit;
            }
            if ($arg=="live")
            while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {;
                print $row['Valuta']."!".$row['live']."\n";
                exit;
            }

            if ($arg=="bnr")
            while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {;
                print $row['Valuta']."!".$row['bnr']."\n";
                exit;
            }

        }
        elseif ($cmd == "get") {
                $arg = $arg1;
                $index = $arg2;
                $query="select * from curs where Valuta='".$index."'";
                $result = mysql_query($query);
                $row = mysql_fetch_array($result,MYSQL_ASSOC);
                if ($arg=='bnr' && $row['Valuta']==$index) print $row['bnr']."\n";
                if ($arg=='live' && $row['Valuta']==$index) print $row['live']."\n";
        }
}

?>

Code: Select all

+--------+----------+---------+---------------------------+-----------------------------+
| Valuta | bnr      | live    | DescriereRO               | DescriereEN                 |
+--------+----------+---------+---------------------------+-----------------------------+
| AUD    |   2.3078 |  2.3169 | Dolarul australian        | Australian Dollar           |
| BGN    |   2.1692 |  2.1711 | Leva bulgareasca          | Bulgarian Lev               |
ss_dobanzi is 90% the same thing.

Anyway, I don't know if the script is the problem here, but is ok to return a value for this? this-should-return-an-error-too-php ss_dobanzi get valoare LIBOREUR6M
[url=http://www.x-graphs.com/]http://www.x-graphs.com[/url] [color=red]X[/color]-[color=blue]graphs[/color] :: All kind of graphs
User avatar
Alice
Cacti User
Posts: 111
Joined: Tue Oct 28, 2003 4:54 pm
Location: Bucharest, RO.

Post by Alice »

I've played a little with the ss_valute.php script and, at some moment, it returned erroneus values. That's OK.

BUT the graphs that were using ss_dobanzi.php (another script, another table, etc) went crazy too!

-------------------------

Okie, that made me look at the scripts from another server (made by me too, but a long while ago).

The old scripts were using:
return(trim($value));

The new scripts were using:
print $value."\n";


Can this be the problem?
[url=http://www.x-graphs.com/]http://www.x-graphs.com[/url] [color=red]X[/color]-[color=blue]graphs[/color] :: All kind of graphs
User avatar
BSOD2600
Cacti Moderator
Posts: 12171
Joined: Sat May 08, 2004 12:44 pm
Location: USA

Post by BSOD2600 »

Quite possibly. Cacti (and especially spine) can be picky about a scripts returned values. Any extra spaces, trailing characters, etc can break stuff. Why not throw that trim() onto your new script and see if it helps things? All those U's getting returned, certainly cannot be a good thing either.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests