Data Input Methods with more one output fields

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

Moderators: Developers, Moderators

Post Reply
juvann
Posts: 20
Joined: Mon Dec 18, 2006 4:04 am

Data Input Methods with more one output fields

Post by juvann »

Hi,

Can I create a data input methods which return more fields with one query?
Explain it with more details. I would interrogate a database which not
support SNMP and so I develop a script for query. On the machine I have more database. I create a DataQuery and a XML for list of database. My script support command get, index and query. When insert the "Associated Data Queries" in my devices cacti invoke my script first with parameter index and after with parameter query. After I create a data source for one of list return, cacti invoke my script with get but it take all output for one field.

Script

Code: Select all

function ss_database($hostname, $user, $pass,$cmd, $arg1 = "", $arg2 = "") {
        if ($cmd == "index" || $cmd == "query") {
                $dblist = list_database($hostname,$user,$pass);
                for($i=0;($i<sizeof($dblist));$i++) {
                        if($cmd == "index")
                                echo $dblist[$i] . "\n";
                        else
                                echo $dblist[$i] . '!' . $dblist[$i] . "\n";
                }
        } elseif ($cmd == "get") {
                echo "field1!10 field2!20";
        }
}
XML

Code: Select all


<query>
        <name>Database</name>
        <script_path>|path_php_binary| -q |path_cacti|/scripts/script.php</script_path>
        <arg_prepend>|host_hostname| |host_snmp_username| |host_snmp_password|</arg_prepend>
        <arg_index>index</arg_index>
        <arg_query>query</arg_query>
        <arg_get>get</arg_get>
        <output_delimeter>!</output_delimeter>
        <index_order>DatabaseName</index_order>
        <index_order_type>alphabetic</index_order_type>
        <index_title_format>Database Name|chosen_order_field|</index_title_format>

        <fields>
                <DatabaseName>
                        <name>Database Name</name>
                        <direction>input</direction>
                        <query_name>index</query_name>
                </DatabaseName>

                <Output>
                        <name>Output</name>
                        <direction>output</direction>
                        <query_name>output</query_name>
                </Output>
        </fields>
</query>

My Data Input Fields:

Input Fields
Name Field Order Friendly Name
index_type 0 (Not In Use) Index Type Delete
index_value 0 (Not In Use) Index Value Delete
output_type 0 (Not In Use) Output Type ID Delete

Output Fields
Name Field Order Friendly Name Update RRA
field1 0 (Not In Use) Field1 Selected Delete
field2 0 (Not In Use) Field2 Selected Delete

On data query I associate the same field output to 2 data source but I think is not correct.

Thanks for help
Giovanni
juvann
Posts: 20
Joined: Mon Dec 18, 2006 4:04 am

Post by juvann »

Why cacti invoke my script with argument get and not query?

I read this from manual:

Script Query XML Syntax

output: Output values are "unknown" values that are returned from the script. A script query may return multiple statistics for a single index. For instance, a single partition could return free disk space, total disk space, fragmentation percentage, etc.

I searched for example but not work as the document tell.
The script query_unix_partitions.pl return one value for each index but not all value for a single index.
juvann
Posts: 20
Joined: Mon Dec 18, 2006 4:04 am

Post by juvann »

I am using cacti 0.8.6i
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Please check http://docs.cacti.net/node/284 for a walkthrough on Script Data Queries.
Reinhard
juvann
Posts: 20
Joined: Mon Dec 18, 2006 4:04 am

Post by juvann »

Explain better my real problem.
I would monitoring a database, I develop the script and xml, all works.
But I would improve the script. My script make a connection to database for each value and for each database, which I want to retrieve. For example if I want locks and bufferhits of 2 databases, I need make 4 connection to same server, because cacti call me my script with parameter get, so I can return only a value. When I need retrieve 10 value for each database the number of connections is very high.
In this moment all works with this code:

Script

Code: Select all

function ss_database($hostname, $user, $pass,$cmd, $arg1 = "", $arg2 = "") {
        if ($cmd == "index" || $cmd == "query")
        {
                $dblist = list_database($hostname,$user,$pass);
                for($i=0;($i<sizeof($dblist));$i++)
                {
                        if($cmd == "index")
                                echo $dblist[$i] . "\n";
                        else if($arg1 == "database")
                                echo $dblist[$i] . '!' . $dblist[$i] . "\n";
                }
        }
        elseif ($cmd == "get")
                return get_property($hostname,$user,$pass,$arg2,$arg1);
}
but there are 18 connections to server, 3 databases, 6 value for each databases. If I can make only 3 connections to server is better.
Is there a solution?

Thanks for help
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

AFAIK, this is (currently) not possible using your approach.
While this approach is a good one, in principle, it is not the best performing one. To make it faster, you perhaps will have to consider re-writing it as a Data Input Method that prints all needed parameters in one run.
Of course, this will loose flexibility.
Reinhard
juvann
Posts: 20
Joined: Mon Dec 18, 2006 4:04 am

Post by juvann »

gandalf thanks very much for the help.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests