Welcome to Pandora FMS Community!

Find answers, ask questions, and connect with our community around the world.

Welcome to Pandora FMS Community Forums Community support post process not working?

  • post process not working?

    Posted by tonovd on July 15, 2008 at 09:34

    Hi all,

    I am a pandora newbie, so big change it’s me doing something wrong.

    I have made a network-module to fetch snmp data from one of my servers (used disk space), and having 2 problems with that :

    1. the module does collect data, but not at the specified interval. For test purposes I’ve set the interval at 10 seconds, but he seems to collect data every 4 or 5 minutes. Also the timeinterval at the agent is set at 10

    2. I need to multiply that data with 4096 to get the correct used size in bytes. I’ve entered 4096 in the post-process box, but if i view the data, it doesn’t seem to have multiplied this . Is there someting i am missing here?

    Here working with pandora 2.0, build 080226

    greets,

    Sancho replied 16 years, 7 months ago 4 Members · 10 Replies
  • 10 Replies
  • tonovd

    Member
    July 16, 2008 at 05:43
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    Well, since everybody seems to be on holiday, and i had some time to spare, i figure the “post_process” problem myself : it doesn’t seem to be implemented in Pandora 2.0 the data is fetched, but no program logic is foreseen in the pandora_network script to multiply it with the post process value. I changed the code somewhat, so that it takes it now into account (at least for snmp_data)

    On doing that, i stumbled on another problem.I was querying the used space of a hard disc. datos_agente.php does make from every double that has no decimals and integer, and then you run into problems if your double is bigger then 2,147,483,647 (the max value for an integer), so i never saw my exact used space (which was more then 2,147,843,647 bytes of course). I’ve changed the code there also ,so that it doesn’t do the intval() for values above 1 1,000 (values higher then that are handle by format_for_graph)

    I’ve no problem sharing my code, if i knew how 🙂

    The only problem still remaining for me is why i don’t get data every 10 or 300 seconds, but at random intervals varying between 5 mintes and a half hour.

    But hey, i am still a newbie…

  • esteban

    Member
    July 16, 2008 at 07:42
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    Hi tono,

    Yes, some of us are in holidays, so replying emails and forums is quite slow right now.

    I have seen in SVN code the code about long numbers, and you’re right, by using intval() the value could be stripped… I’m thinking about a better solution. I don’t know why is it checking decimals if format_for_graph() does all that checks. Can you replace that chunk of code with this one?

    if (is_numeric($row["datos"])) {
    	echo format_for_graph ($row["datos"]);
    } else {

    After doing that, please tell me if it works for you and also if the results are not stripped.

    Sharing your changes:

    There are many ways to share your code with us. The first one is adding here the code between [ code ] and [ /code ] (whitout blankspaces) so it’s well formated by the forum. You can add all the code you changed or add the result of executing:

    diff -u previous_file.php new_file.php

    Of course, you must save original file before doing any changes or you can’t compare with any file. If you’re using SVN version, you can simply run:

    svn diff changed_file.php

    You can also send the result of the diff to our Pandora development list at [email protected]

    Greetings!!

  • tonovd

    Member
    July 16, 2008 at 10:10
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    hi esteban,

    That did the trick yes….I also added this code to format_for_graph :

     if (fmod ($number, 1000000000) > 0){
                            return number_format ($number / 1000000000, $decimals, $dec_point, $thousands_sep)." G";
                              }
    

    That way my 5,6 Gb will be represented as 5,6 G instead of 5,600 K
    I’ve noticed that they used that method (changing a double to an int with intval()) in other scripts also, i’ll try to make a list of where i found them by this evening, and post it in pandora-develop.

    For completeness, here the changes i made in pandora_network :

    sub exec_network_module {
            my $pa_config = $_[0];
            my $id_agente_modulo = $_[1];
            my $dbh = $_[2];
            # Init variables
            my $id_agente;
            my $id_tipo_modulo;
            my $nombre;
            my $min;
            my $max;
            my $module_interval;
            my $tcp_port;
            my $tcp_send;
            my $tcp_rcv;
            my $snmp_community;
            my $snmp_oid;
            my $ip_target;
            my $id_module_group;
            my $flag;
            my $post_process;
            my @sql_data;
            if ((!defined($id_agente_modulo)) || ($id_agente_modulo eq "")){
                    return 0;
            }
    
       if (@sql_data = $exec_sql->fetchrow_array()){
                    $id_agente= $sql_data[1];
                    $id_tipo_modulo = $sql_data[2];
                    $nombre = $sql_data[4];
                    $min = $sql_data[6];
                    $max = $sql_data[5];
                    $module_interval = $sql_data[7];
                    $tcp_port = $sql_data[8];
                    $tcp_send = $sql_data[9];
                    $tcp_rcv = $sql_data[10];
                    $snmp_community = $sql_data[11];
                    $snmp_oid = $sql_data[12];
                    $ip_target = $sql_data[13];
                    $id_module_group = $sql_data[14];
                    $flag = $sql_data[15];
                    $post_process = $sql_data[23];
                    $exec_sql->finish();
    
        } else {
                                                $module_data = $temp2;
                                                 ##post_process calculation
                                                    if ($post_process != 0) {
                                                $module_data = $post_process * $temp2;
                                                    }
                                        }
    

    i’ll post that also at pandora-develop, but if someone is googling this, he has the solution.

    greetz.

  • esteban

    Member
    July 17, 2008 at 04:21
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    Hi tono,

    The chunks of codes are not shown well, you have to use [ code ] instead of
    🙂

    And they’re not diffs, but the code itself, so it’s very difficult to see what you really changed… Can you try doing the diffs like I said in the previous post?

    You can also use SVN code to be on the edge and help us to improve the code (submitting patches will be easier for you). Do you need some help on that?

    The “G” trick is also nice, I will add it to the trunk code 🙂

    See ya

  • raul

    Member
    July 17, 2008 at 06:26
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    Esteban, Tono, I edited tono’s post and changed from div to code

    Raúl

  • esteban

    Member
    July 17, 2008 at 07:17
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    Thanks Raul, although it doesn’t change too much since I still need the diff instead of the whole code 🙂

  • tonovd

    Member
    July 18, 2008 at 03:35
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    sorry for the delay but here the diffs :

    for functions.php (for format_for_graph)

    424a425,430
    >               //echo $number ."***";
    >          if ($number > 1000000000) {
    >                 if (fmod ($number, 1000000000) > 0)
    >                         return number_format ($number / 1000000000, $decimals,                                                                               $dec_point, $thousands_sep)." G";
    >          //       return number_format ($number / 1000000000, 0, $dec_point, $                                                                              thousands_sep)." G";
    >         }
    

    in pandora_network

    532a536
    >       my $post_process;
    554a559
    >               $post_process = $sql_data[23];
    614a620,623
    >                                            ##post_process calculation
    >                                               if ($post_process != 0) {
    >                                           $module_data = $post_process * $temp2;
    >                                               }
    

    and for datos_agente.php

    94,99c94,96
    <                               $mytempdata = fmod($row["datos"], 1);
    <                               if ($mytempdata == 0)
    <                                       $myvalue = intval($row["datos"]);
    <                               else
    <                                       $myvalue = $row["datos"];
                                   //$mytempdata = fmod($row["datos"], 1);
    >                               $myvalue = $row["datos"];
    >                                echo format_for_graph($myvalue);
    

    I hope that’s more workable for you. and i have no idea how svn works, so any help would be appreciated….

  • esteban

    Member
    July 18, 2008 at 04:15
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    It’s almost what we need… You forget “-u” flag on diff execution. Run:

    diff -u previous_file new_file

    To get SVN trunk version, you have to execute the following command to get Pandora console:

    svn co https://pandora.svn.sourceforge.net/svnroot/pandora/trunk/pandora_console pandora_console

    And to get Pandora server:

    svn co https://pandora.svn.sourceforge.net/svnroot/pandora/trunk/pandora_server pandora_server
    
    To work with SVN, simply do your changes in that directory and afterwards run "svn diff" and paste the result. You can also see our new developments (although updating from 1.3.x is not yet implemented). This is the best way to help with Pandora 2.0 :)
    
    If it's too complicated for you, simply run diff (with -u flag!) and we will do the job. But if you want to really help us, using SVN is the only way :)
  • tonovd

    Member
    July 18, 2008 at 07:18
    0 Karma points
    Community rank: tentacle-noob-1 Tentacle noob
    Like it
    Up
    0
    Down
    Drop it
    ::

    ok..with -u this time 🙂

    for functions.php (for format_for_graph)

    --- /root/trunk/pandora_console/include/functions.php   2008-07-16 09:24:34.000000000 +0200
    +++ /var/www/pandora_console/include/functions.php      2008-07-16 16:49:07.000000000 +0200
    @@ -422,6 +422,12 @@
      * @return A number rendered to be displayed gently on a graph.
      */
     function format_for_graph ($number , $decimals = 1, $dec_point = ".", $thousands_sep = ",") {
    +               //echo $number ."***";
    +          if ($number > 1000000000) {
    +                if (fmod ($number, 1000000000) > 0)
    +                        return number_format ($number / 1000000000, $decimals, $dec_point, $thousands_sep)." G";
    +         //       return number_format ($number / 1000000000, 0, $dec_point, $thousands_sep)." G";
    +        }
            if ($number > 1000000) {
                    if (fmod ($number, 1000000) > 0)
                            return number_format ($number / 1000000, $decimals, $dec_point, $thousands_sep)." M";
    

    in pandora_network

    --- /root/trunk/pandora_server/bin/pandora_network      2008-07-14 14:07:52.000000000 +0200
    +++ /usr/bin/pandora_network    2008-07-16 10:35:06.000000000 +0200
    @@ -2,6 +2,9 @@
    
     eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
         if 0; # not running under some shell
    +
    +eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    +    if 0; # not running under some shell
     ##########################################################################
     # Pandora FMS Network Server
     ##########################################################################
    @@ -530,6 +533,7 @@
            my $ip_target;
            my $id_module_group;
            my $flag;
    +       my $post_process;
            my @sql_data;
            if ((!defined($id_agente_modulo)) || ($id_agente_modulo eq "")){
                    return 0;
    @@ -552,6 +556,7 @@
                    $ip_target = $sql_data[13];
                    $id_module_group = $sql_data[14];
                    $flag = $sql_data[15];
    +               $post_process = $sql_data[23];
                    $exec_sql->finish();
            } else {
                    $exec_sql->finish();
    @@ -612,6 +617,10 @@
                                                $module_result = 1;
                                        } else {
                                                $module_data = $temp2;
    +                                            ##post_process calculation
    +                                               if ($post_process != 0) {
    +                                           $module_data = $post_process * $temp2;
    +                                               }
                                        }
                                } else { # String SNMP
                                        $module_data = $temp2;
    

    and for datos_agente.php

    --- /root/trunk/pandora_console/operation/agentes/datos_agente.php      2008-07-16 09:24:36.000000000 +0200
    +++ /var/www/pandora_console/operation/agentes/datos_agente.php 2008-07-18 10:29:54.000000000 +0200
    @@ -91,12 +91,9 @@
                            echo "".$row["timestamp"]."";
                            echo "";
                            if (is_numeric($row["datos"])) {
    -                               $mytempdata = fmod($row["datos"], 1);
    -                               if ($mytempdata == 0)
    -                                       $myvalue = intval($row["datos"]);
    -                               else
    -                                       $myvalue = $row["datos"];
    -                               echo format_for_graph($myvalue );
    +                               //$mytempdata = fmod($row["datos"], 1);
    +                               $myvalue = $row["datos"];
    +                                echo format_for_graph($myvalue);
                            } else {
                                    echo salida_limpia($row["datos"]);
                            }
    

    next time i will use the svn -way.

  • Sancho

    Administrator
    July 22, 2008 at 17:50
    2321 Karma points
    Community awards: bulb Bright ideas
    Community rank: tentacle_master_icon Tentacle Master
    Like it
    Up
    0
    Down
    Drop it
    ::

    Hey. I want to review your changes to apply your code to current code. Could you send the patch with the lastest SVN code and upload the patch / diff files in the forum as attachment ?. Review or try to apply patch with code posted in web forum is a pain in the ass.

    Today I’ve written the first version of postprocess code for Pandora FMS 2.0. If you want to check it, just make

    svn update

    On your server directory.