Daily diskspace alerts using OCS Inventory NG

Being proactive about managing system capacity is always a good idea. If you happen to use the OCS Inventory NG tool then here is a way for you to automatically have reports emailed to you (or various people) regarding systems with disk capacity below a threshold you set in a configuration file. This solution is geared towards Windows Servers, but you can easily change the select statement and use a different criteria (change where osname like ‘%server%’ to suit yourself). The results are sent as an attached CSV file, so you can easily view it in Excel or Open Office or even using vi if that is suits your fancy.

The percentage free space threshold, along with email addresses and domain names (aka workgroup names) are configured in a file named ocsdiff_conf.php. I run this (and other reports which I may post later) from a new subdirectory named reports that I created under /var/www/html/ocsreports. Be sure to set the same ownership and permissions on files in this directory as the other files under ocsreports. Here is what the file looks like:

> ocsdiff_conf.php

The file is named like this because the first report I wrote was to generate reports on hardware changes (RAM and disk in particular). I know reports like this can be implemented using GLPI integration – but we already have a helpdesk/ticketing system and I just can’t justify the effort to setup GLPI when writing one’s own reports is just not that hard.

The report itself is contained in the code below, I named the file diskreport.php and I scheduled it to run everyday using cron. I run my cron jobs for OCS-NG reports under the apache account.

> diskreport.php

Be sure to change the From and Reply To addresses in at the top of the file to suit yourself. If I have time I will move this to the configuration file.

My version of OCS-NG displays 4020 on the screen, I believe this equates to V1.0 (I know 1.01 is released, but just haven’t had the time to upgrade yet). I am running on RHEL 4.

Use the link below to download a zip file of both of these files. If you have any comments or questions post a comment on this post and I will reply.

Download OCS-NG Diskspace Report Version 1.0

24 Responses to “Daily diskspace alerts using OCS Inventory NG”

  1. Mark Egghead says:

    SAManage is a leading provider of on-demand IT Asset Management services built using OCS-NG technology. Our service helps companies of all sizes effectively manage IT Assets, organize software licenses and detect risks and license compliance gaps. With no software or servers required, SAManage’s on-demand service can be easily deployed across multiple locations within minutes and provide visibility into complex IT infrastructures to ensure optimized IT asset utilization. For more information or to sign-up for a free 30-Days Trial, visit http://www.samanage.com or call 1-888-250-8971.

  2. sarfraz says:

    We are installing both in RHEL5 we got the alert but when we changing any hardware we didi not got alert can you help us.

  3. Mike says:

    Hi sarfraz,

    What do you mean by changing hardware? Are you altering the hardware to simulate a low % of free disk space? Or were you expecting this utility to generate alerts on ahrdware changes?

  4. sarfraz says:

    I means, we are using this script for change management we can use it if not tel us and also we are getting alert but in attachment only we got this line
    “Computer Name,Drive Letter,Type,Filesystem,Total,Free,Free %”

    PLEASE HELP US.

  5. Marcelo says:

    Hi Mike!

    i’m using ocsreport and i am search a tool that show me the changes in the machine with ocs-agent… this script(diskreport.php) show me the the disk-space but i don’t understand with put in the code! :S

    can you help me?

  6. Raman Pillai says:

    Hi,
    It was great to have a script to check disk space. It would be great if you could send me the OCSdiff script which sends mail of the difference to the hardware changes in the system.

    Thanks in Advance.

    Raman

  7. [...] the OCS NG database.  This script is implemented much like the daily disk reports from OCS (see this).  Sorry there is no better documentation for this, I just have not had the time and soon will no [...]

  8. Gabriel Sepulveda says:

    in which folder on the ocsreports should I put these files?, or how do I use it?

  9. Gabriel Sepulveda says:

    dont worry, I just got the case closed. Thank you for these scripts.

  10. Mike says:

    Glad you figured it out Gabriel

  11. Anonymous says:

    Good job there are work on 1.3 too.

  12. Felipe says:

    Hi All,

    Does anyone have a script to send alerts whenever a new software is installed on any of computers which have OCS client installed?

    Regards.

  13. Mike says:

    I suggest you take a look at GLPI, it has this capability when integrated with OCS-NG

    Mike

  14. Felipe says:

    Tks Mike.. I’ve already installed GLPI and integrated OCS plugin within it. However, I didn’t find much info regarding setting up this kind of alert on GLPI. If you know any source where I can get some how to, I’d really appreciate.

    Regards;

  15. Mike says:

    How about a search of software where date is less than X. So if you wanted a listing of all new software installed in the last month use <1 in the date field of the search?

    Not sure, I don't currently have access to running instances of either OCS-NG or GLPI, but this link gives me that idea…

    You might also check out this plugin, it is light on documentation so you might just have to try it to see what it does.

    Sorry I can’t be of more help, but as I said I don’t currently have access to these tools. Best of luck,
    Mike

  16. ganesh rane says:

    unable to run the script giving following error
    ./ocsdiff_conf.php: line 1: ?php: No such file or directory
    ./ocsdiff_conf.php: line 6: =: command not found
    ./ocsdiff_conf.php: line 7: =: command not found
    ./ocsdiff_conf.php: line 8: =: command not found
    ./ocsdiff_conf.php: line 9: =: command not found
    ./ocsdiff_conf.php: line 10: =: command not found
    ./ocsdiff_conf.php: line 11: =: command not found
    ./ocsdiff_conf.php: line 12: syntax error near unexpected token `(‘
    ./ocsdiff_conf.php: line 12: `$domains = array(‘

  17. Mike says:

    Why are you trying to run the config file, you would run the diskreport.php file which would load the configuration file. That said there is no reason the file should not run if you have the appropriate permissions set, have PHP installed, and call it correctly. Typically the report file is run from a cron job where PHP is called and the file name is passed to the PHP interpreter. If for some reason you want to run this form the command line you must use the command:

    php -f filename.php

    If that doesn’t help then please let me know how you are running the file and what version of PHP you are using.

  18. ganesh rane says:

    [root@glpi reports]# php -f ocsdiff.php
    PHP Parse error: syntax error, unexpected T_STRING in /var/www/html/ocsreports/reports/ocsdiff.php on line 14

  19. ganesh rane says:

    [root@glpi reports]# php -f ocsdiff.php
    PHP Notice: Undefined variable: curramresults in /var/www/html/ocsreports/reports/ocsdiff.php on line 112
    PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /var/www/html/ocsreports/reports/ocsdiff.php on line 112
    PHP Notice: Undefined variable: snapramresults in /var/www/html/ocsreports/reports/ocsdiff.php on line 113
    PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /var/www/html/ocsreports/reports/ocsdiff.php on line 113
    PHP Notice: Undefined variable: currdiskresults in /var/www/html/ocsreports/reports/ocsdiff.php on line 114
    PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /var/www/html/ocsreports/reports/ocsdiff.php on line 114
    PHP Notice: Undefined variable: snapdiskresults in /var/www/html/ocsreports/reports/ocsdiff.php on line 115
    PHP Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /var/www/html/ocsreports/reports/ocsdiff.php on line 115

  20. Mike says:

    Do you have both the config file and the diff script in the same directory with the appropriate permissions (read and execute)? In your first comment it says unexpected string on line 14… what do you have at line 14 in your script? Line 14 in my script is:

    $headers .= “Reply-To: ITInventory@yourdomain.com“;

    What does your line 14 look like?

    Lets deal with the errors one at a time and start with the first before we move on.

  21. ganesh rane says:

    pls provide the solution

  22. Mike says:

    I am trying to help you, please provide the information requested…

    Here is what I get when I run it on my host:
    [~]# php -f ocsdiff.php
    [~]#

    Here are what my permissions look like:
    [~]# ls -al ocsdiff.php
    -rw-r–r– 1 usermasked groupmasked 5433 Dec 19 16:06 ocsdiff.php

    Did you do something like download to Windows, edit it there and then upload it to your Linux/UNIX host? If so you may want to download it directly to the UNIX host and edit it there. Windows has a nasty habit of converting line endings in UNIX (line feed) to CR and LF, so that could also be the root of your problem.

    As noted, I am trying to help you but you also need to play a part in this …. Cura te ipsum

  23. ganesh rane says:

    [root@glpi reports]# ls -al ocsdiff.php
    -rwxrwxrwx 1 root root 5444 Dec 19 18:04 ocsdiff.php

    I am downloading the file the windows and cpoy it to unix using winscp and than edit in linux itself.

    Regards,
    Ganesh Rane

Leave a Response