Ad Widget

Collapse

Count number files into a windows directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • patrick1140
    Junior Member
    • Dec 2010
    • 2

    #1

    Count number files into a windows directory

    Hello,

    An beguinner question...

    I've a Mailserver running under windows (mdeamon) and i want check the number of mail in queues.

    To to it i want count the # of files in e:\mdaemon\queues\xxx\xxx

    Any idea ?

    Thanks
  • patrick1140
    Junior Member
    • Dec 2010
    • 2

    #2
    Found :-)

    This is how I monitor the size of a directory on a windows machine:

    1. fill in the correct zabbix-server-IP and de correct hostname of the windows system
    in the commandstring in the vb-script (see below)
    2. save the vb-script as c:\zabbix\dir_size.vbs on the windows system to be monitored.
    3. add userparameter in the zabbix_agentd.conf:
    UserParameter=dir_size[*],cscript.exe c:\zabbix\dir_size.vbs $1
    4. restart zabbix agent
    5. create 2 items in zabbix:

    first one:
    description: whatever
    type: zabbix trapper
    key: tr_dir_size
    type: numeric

    second one:
    description: tr_dir_size
    type: zabbix agent
    key: dir_size[c:\root\sub]
    type: text
    interval: 300

    explanation: the second one makes the zabbix agent execute the script every 300 seconds, while the first one catches the output of the script. The output is the size of directory c:\root\sub in bytes

    The script itself:

    Dim oF, oFS, dirsize
    directory = WScript.Arguments(0)
    Set objFS = CreateObject("Scripting.FileSystemObject")
    set oF = oFS.GetFolder(directory)
    dirsize = oF.Size
    Set WshShell = CreateObject("wscript.Shell")
    commandstring="c:\zabbix\zabbix_sender.exe -z ZBX_IP -s HOST_NAME -k tr_dir_size -o " & dirsize
    WshShell.Run commandstring,0
    WScript.Quit

    Comment

    • Zaniwoop
      Senior Member
      • Jan 2010
      • 232

      #3
      I think you are complicating this by creating 2 items.

      Rather than have the script execute the zabbix_sender to return the value, write the output of dirsize to standard output. This will return the value you require to the calling item.

      my script to return the number of files looks like this:
      Code:
      Option Explicit
      Dim objFSO, objFolder, FolderName
      Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
      FolderName = Replace(WScript.Arguments(0),"/","\")
      Set objFolder = objFSO.GetFolder(FolderName)
      WScript.StdOut.Write objFolder.Files.Count
      Set objFolder = Nothing
      Set objFSO = Nothing
      WScript.Quit(0)
      It changes forward-slashes to backslashes, as the zabbix_agentd doesn't like having backslashes passed in wildcard parameters

      You need to run the script with the //nologo parameter

      Code:
      UserParameter=FileCount[*],cscript c:\FileCount.vbs [B]//nologo[/B] $1
      To use this, you need to create an item with a key FileCount[e:/mdaemon/queues/xxx/xxx], of type numeric decimal. (Notice the use of forward-slashes)

      Comment

      • qix
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Oct 2006
        • 423

        #4
        I like how you made it a wildcard item
        This will allow setting template and host macros to support different install locations. Use the macro for the wildcard, and you're set.
        With kind regards,

        Raymond

        Comment

        • Josh
          Junior Member
          • Dec 2011
          • 10

          #5
          I used the second method listed in this thread to count files on a win 2003 and 2008 server but it does not seem to work on win 2000 which is what I really needed this for. I can run the script just fine on the box and will give the correct number of files in the specified directory but Zabbix is having a hard time retrieving this number when it does it remotely. Is there a reg key or something I need to modify to allow Zabbix to do this in server 2000?

          Comment

          • qix
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Oct 2006
            • 423

            #6
            Can you use other vb scripts as userparameters? Maybe vb scripting isn't working ok for the agent. Try it with a simple script that just echoes a string and see if that works.
            With kind regards,

            Raymond

            Comment

            • Zaniwoop
              Senior Member
              • Jan 2010
              • 232

              #7
              The VB Script above does work with the agent.

              Comment

              • qix
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • Oct 2006
                • 423

                #8
                I was refering to Josh problem on that specific host.
                With kind regards,

                Raymond

                Comment

                • Josh
                  Junior Member
                  • Dec 2011
                  • 10

                  #9
                  Well the script does work on that host and returns the number of files. This is the error I am seeing in the log file and in the zabbix console.

                  4176:20111201:095651.828 unable to set job info: [0x00000057] The parameter is incorrect.

                  And this is my parameter

                  UserParameter=FileCount[*],cscript c:\FileCount.vbs //nologo $1

                  Comment

                  • Zaniwoop
                    Senior Member
                    • Jan 2010
                    • 232

                    #10
                    post a screen shot of the item...

                    Comment

                    • Josh
                      Junior Member
                      • Dec 2011
                      • 10

                      #11
                      Here is the screen shot of the item.
                      Attached Files

                      Comment

                      • Zaniwoop
                        Senior Member
                        • Jan 2010
                        • 232

                        #12
                        Ok, the only difference I see is my items' type is Zabbix agent (active)

                        Comment

                        • Josh
                          Junior Member
                          • Dec 2011
                          • 10

                          #13
                          And your is on server 2000?

                          Comment

                          • Josh
                            Junior Member
                            • Dec 2011
                            • 10

                            #14
                            This is the error message on the zabbix console. It looks like the server is passing the error back to zabbix and zabbix is saying "this is not a number". So it must be something that is happening when zabbix is asking the server to run that vbscript. Also, I changed the name of the Item so dont let that throw you off.
                            Attached Files

                            Comment

                            • qix
                              Senior Member
                              Zabbix Certified SpecialistZabbix Certified Professional
                              • Oct 2006
                              • 423

                              #15
                              Could be the agent sends a tab, space or linefeed or whatever. Does it store data when set to character or text?
                              With kind regards,

                              Raymond

                              Comment

                              Working...