Ad Widget

Collapse

Disk space report

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StephenJ
    Member
    • Dec 2018
    • 44

    #1

    Disk space report

    We are currently running Zabbix server 4.0.4 on Centos 7. One of our customers has a reporting requirement. They would like a report produced each month shown total size of each drive on each server and free space on each drive on each server.

    Is there a report I can setup to do this?


    On our old zabbix server we use the following sql command to pull the necessary information

    <form action="./index.php" method="post" >
    Group Name:<br>
    <input type="text" name="groupname" value="Enter Group Name"><br>

    <input type="submit" value="Submit">
    </form>
    <?php
    }else{

    echo "Zabbix Trigger Report ".$_POST['groupname']."<br>";
    $output= "Zabbix Trigger Report ".$_POST['groupname']."<br>";
    include 'db.php';
    if(strpos($_POST['groupname'],"DISK") > 0){
    $groupname = explode(",",$_POST['groupname'])[0];
    $sql = "SELECT host, g.name,i.key_ , (Select value_avg from zabbix.trends_uint where itemid = i.itemid order by clock desc LIMIT 1 )/1024/1024/1024 as avg_value
    FROM items i
    INNER JOIN hosts h ON ( i.hostid = h.hostid )
    INNER JOIN hosts_groups hg ON ( hg.hostid = h.hostid )
    INNER JOIN groups g ON ( g.groupid = hg.groupid )
    WHERE g.name = '".$groupname."' AND i.key_ like 'vfs.fs.size%' AND i.key_ not like '%#%' and i.key_ not like '%pfree%'

    ORDER BY host asc";
    echo "Host,Group,Key,Size(GB)<br>".PHP_EOL;
    $result = $conn->query($sql);
    $count = 0;
    if ($result->num_rows > 0) {
    // output data of each row
    $count++;
    $hosts_triggers = "";

    while($row = $result->fetch_assoc()) {
    echo $row['host'].",".$row['name'].",".$row['key_'].",".round($row['avg_value'],2)."<br>".PHP_EOL;
    }
    } else {
    echo "0 results";
    }


    The problem is on zabbix 4.0.4 the table "groups" no longer exists. I am not sure how to convert the sql command to get it to work with version 4.0.4
    Last edited by StephenJ; 14-02-2019, 17:55.
  • StephenJ
    Member
    • Dec 2018
    • 44

    #2
    I have included the full php file we use. Looking at the zabbix database I can see the "group" table is missing. I am not sure what i would need to change it to. Basically this webpage sits on the zabbix server, you type in the host group name. The SQL command then queries the database, brings back all the servers in the group, along with total space and free space for all drives.

    If somebody could point me in the direction of getting it working on 4.0.4 it would be appreciated.

    To test copy the folder into directory /var/www edit the db.php and put in your username and password to connect to your database.
    Attached Files

    Comment

    • StephenJ
      Member
      • Dec 2018
      • 44

      #3
      Got it sorted. Found out what tables I needed to pull the info from.

      Comment

      • kloczek
        Senior Member
        • Jun 2006
        • 1771

        #4
        BTW. On Using zabbix you should be not be using direct SQL queries.
        Zabbix API is for this kind of operations.
        http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
        https://kloczek.wordpress.com/
        zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
        My zabbix templates https://github.com/kloczek/zabbix-templates

        Comment

        Working...