Data Querie : How could they return information ?

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

Post Reply
Taryck
Posts: 9
Joined: Sat Feb 04, 2017 4:51 pm

Data Querie : How could they return information ?

Post by Taryck »

Hi All,

I've created a Data Query for disk with the following fields :
  • id => Disk serial number as it's an invariant : WD-WX21D947N976
    disk => Device path /dev/sda /dev/sdb
    model => The disk model : WDC WD50EZRX-00MVLB1
    status => active ,idle, standby, sleeping
    on_off => number between 0 and 1
    power => Power consuption in W
    temp => Disk Temperature from Smart attributes
    up_time => Hours Disk is UP from Smart attributes
    start_count => Number of disk start from Smart attributes
here is the xml :

Code: Select all

<interface>
        <name>Get Linux Disks</name>
        <description>Queries a list of disks on a unix-based host with /sys/block/.</description>
        <script_path>perl |path_cacti|/scripts/query_unix_disks.pl</script_path>
        <arg_index>index</arg_index>
        <arg_query>query</arg_query>
        <arg_get>get</arg_get>
        <arg_num_indexes>num_indexes</arg_num_indexes>
        <output_delimeter>:</output_delimeter>
        <index_order>dskSerial</index_order>
        <index_order_type>alphabetic</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <dskSerial>
                        <name>Disk ID (Serial)</name>
                        <direction>input</direction>
                        <query_name>id</query_name>
                </dskSerial>

                <dskDevice>
                        <name>Disk Path</name>
                        <direction>output</direction>
                        <query_name>disk</query_name>
                </dskDevice>
                <dskModel>
                        <name>Model</name>
                        <direction>output</direction>
                        <query_name>model</query_name>
                </dskModel>
                <dskStatus>
                        <name>Status du disque</name>
                        <direction>output</direction>
                        <query_name>status</query_name>
                </dskStatus>
                <dskOn_Off>
                        <name>Etat binaire du disque</name>
                        <direction>output</direction>
                        <query_name>on_off</query_name>
                </dskOn_Off>
                <dskPower>
                        <name>Consomation</name>
                        <direction>output</direction>
                        <query_name>power</query_name>
                </dskPower>
                <dskTemp>
                        <name>Temperature</name>
                        <direction>output</direction>
                        <query_name>temp</query_name>
                </dskTemp>
                <dskUP_Time>
                        <name>Power ON hours</name>
                        <direction>output</direction>
                        <query_name>up_time</query_name>
                </dskUP_Time>
                <dskStart_Count>
                        <name>Disk Start Count</name>
                        <direction>output</direction>
                        <query_name>start_count</query_name>
                </dskStart_Count>
        </fields>
</interface>
However fields (disk, Model and Status does not return numbre but text information.
I use serial as ID (unique) as they do not change at all. Device path /dev/sdX could be impacted by any drive change like adding or removing an existing disk.

I would like to use the disk /dev/sdX attibute and display it as text in the graph. However rddtool reject it and mark as Unknow as it is not an number.

do you have any solution/suggestion ?
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Data Querie : How could they return information ?

Post by netniV »

When you create a script query, one of the parameters is normally to index the device. Because your script is doing this, not the cacti core, you need to provide the index numbers. You may want to use a formula such as converting the 'X' to a number, then adding the partition number to it.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Taryck
Posts: 9
Joined: Sat Feb 04, 2017 4:51 pm

Re: Data Querie : How could they return information ?

Post by Taryck »

Well I've based my script on the one provided by Cacti : query_unix_partitions.pl
Here is the standard interface definition

Code: Select all

<interface>
        <name>Get Unix Mounted Partitions</name>
        <description>Queries a list of mounted partitions on a unix-based host with the 'df' command.</description>
        <script_path>perl |path_cacti|/scripts/query_unix_partitions.pl</script_path>
        <arg_index>index</arg_index>
        <arg_query>query</arg_query>
        <arg_get>get</arg_get>
        <arg_num_indexes>num_indexes</arg_num_indexes>
        <output_delimeter>:</output_delimeter>
        <index_order>dskDevice</index_order>
        <index_order_type>alphabetic</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <dskDevice>
                        <name>Device Name</name>
                        <direction>input</direction>
                        <query_name>device</query_name>
                </dskDevice>
                <dskMount>
                        <name>Mount Point</name>
                        <direction>input</direction>
                        <query_name>mount</query_name>
                </dskMount>

                <dskTotal>
                        <name>Total Blocks</name>
                        <direction>output</direction>
                        <query_name>total</query_name>
                </dskTotal>
                <dskUsed>
                        <name>Used Blocks</name>
                        <direction>output</direction>
                        <query_name>used</query_name>
                </dskUsed>
                <dskAvailable>
                        <name>Available Blocks</name>
                        <direction>output</direction>
                        <query_name>available</query_name>
                </dskAvailable>
                <dskPercentUsed>
                        <name>Percent Used</name>
                        <direction>output</direction>
                        <query_name>percent</query_name>
                </dskPercentUsed>
        </fields>
</interface>
Index is the device name (lvm part ou partition).
And there is a other input that is the mount point.

I've tried to swith device, model into input fields :

Code: Select all

                <dskSerial>
                        <name>Disk ID (Serial)</name>
                        <direction>input</direction>
                        <query_name>id</query_name>
                </dskSerial>

                <dskDevice>
                        <name>Disk Path</name>
                        <direction>input</direction>
                        <query_name>disk</query_name>
                </dskDevice>
                <dskModel>
                        <name>Model</name>
                        <direction>input</direction>
                        <query_name>model</query_name>
                </dskModel>
But they do not appears in the new graph page where mount point do...
What did I miss ?

I'm not sure to understand "You may want to use a formula such as converting the 'X' to a number, then adding the partition number to it."

Here are the results of index call :

Code: Select all

perl query_unix_disks.pl index
WD-WMC1P0H41HPU
WD-WX21D947N976
S21JNSAG111072Y
WD-WX11D557Y7P0
ZA1250ZK
WD-WCAY01298259
WD-WCAVY2252749
WD-WX21D36PPKX9
ZCH06J8Q
WD-WCAVY2269338
WD-WCAVY1896121
WD-WCAVY2403591
and the get on disk attribute

Code: Select all

perl query_unix_disks.pl query disk
WD-WMC1P0H41HPU:/dev/sda
WD-WX21D947N976:/dev/sdb
S21JNSAG111072Y:/dev/sdc
WD-WX11D557Y7P0:/dev/sdd
ZA1250ZK:/dev/sde
WD-WCAY01298259:/dev/sdf
WD-WCAVY2252749:/dev/sdg
WD-WX21D36PPKX9:/dev/sdh
ZCH06J8Q:/dev/sdi
WD-WCAVY2269338:/dev/sdj
WD-WCAVY1896121:/dev/sdk
WD-WCAVY2403591:/dev/sdl
I do not seen any differences with

Code: Select all

perl query_unix_partitions.pl query mount
/dev/mapper/clearos_home-root:/
/dev/mapper/clearos_home-var:/var
/dev/mapper/clearos_home-home:/home
/dev/sdc1:/boot
/dev/mapper/WD_Off-test:/home/test
/dev/mapper/WD_Off-VMs:/mnt/VMs
/dev/mapper/WD_Group-Store:/store/lv_store
/dev/mapper/VG_Backup-Backup_History:/store/backup_history
/dev/mapper/WD_6T_Red-Raid1:/home/raid
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Data Querie : How could they return information ?

Post by netniV »

Check out what the other scripts return on the same sort of parameters.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Taryck
Posts: 9
Joined: Sat Feb 04, 2017 4:51 pm

Re: Data Querie : How could they return information ?

Post by Taryck »

I do not see any difference.
And I do not find any suitable documentation.
Thanks anyway.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest