Ad Widget

Collapse

Scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rudolf
    Member
    • Dec 2004
    • 90

    #1

    Scripts

    Hi all,

    I plan to write a script on our linux computers to gather several infos for zabbix. One single script does for example "ps aux | grep error", and if there is the word "error" in the process list, it writes the value 1 to /tmp/checkresults. Or even the number of lines with errors. If no errors it writes 0. Another command in the script could be "who | wc -l" and add this number to /tmp/checkresults. Like that I want to do several checks, and write the result as a number to the file checkresults, one number per line.

    Then I want to define some UserParameters in agentd.conf on the linux computers where I run the checkresults script in crontab. For example:
    UserParameter=pserrors,cat /tmp/checkresults | head -n 1
    UserParameter=usersonline,cat /tmp/checkresults | head -n 2 | tail -n 1
    ... and so on till the end of the file

    You see my point. The question is, if this "check system" makes sense. Do you think it's a good idea to build something like that? Or do you see some disadvantages?
  • Nate Bell
    Senior Member
    • Feb 2005
    • 141

    #2
    If I'm understanding you correctly, you are using a single script to collect a lot of information, and then store it in a single file. You want to use crontab to schedule when this information is collected, and set up custom Zabbix items to just read from the single results file to report information.
    It sounds like that would work. The benefit is no matter how many items you want to collect, you only have a script file and the results file. it seems there could be a potential problem with timing. The time when crontab runs the script and when Zabbix reads the data may be off, so you get duplicate information stored in Zabbix.
    There also might be an issue of Zabbix trying to read the data file before the script has finished reading it, but this can be fixed by copying all new data to a temporary file, and then moving the new file over top the old file.
    My Zabbix setup uses individual scripts for each custom item, so every machine has several scripts, and ones with important functions have more. The downside is I have a lot of small files to keep track of. The upside is each script can just be copied to another machine if that computer needs a custom item checked.
    So, I suppose the long and the short of it is, yes, your method should work.

    Nate

    Comment

    • Rudolf
      Member
      • Dec 2004
      • 90

      #3
      Thanks for your answer.

      I like it more to have everything in the same place. It's easier (for me) to only have one script file and one output file. If I want to copy the script to another server it's also easier. I just copy the script and add/delete the things I want or don't want on the new server.

      However the problem with crontab and zabbix being on 2 different "timings" also came into my mind. But if I get a zabbix error or warning one minute sooner or later doesn't matter a lot. About your point of writing a data-file by my script and reading it from zabbix at the same time I didn't think about. Maybe I should find a solution for that first. (Well, it won't happen often I guess. maybe 1 in 1000 times, depends on computer speed and the frequency I let the script run).

      Comment

      Working...