Anonymous avatar Anonymous committed b1778bb

Added folderIgnoreFiles

Comments (0)

Files changed (2)

features/poller/cifs-monitor/src/main/java/org/opennms/netmgt/poller/monitors/JCifsMonitor.java

 import jcifs.smb.NtlmPasswordAuthentication;
 import jcifs.smb.SmbException;
 import jcifs.smb.SmbFile;
+import jcifs.smb.SmbFilenameFilter;
 import org.opennms.core.utils.TimeoutTracker;
 import org.opennms.netmgt.model.PollStatus;
 import org.opennms.netmgt.poller.MonitoredService;
         String password = parameters.containsKey("password") ? (String) parameters.get("password") : "";
         String mode = parameters.containsKey("mode") ? ((String) parameters.get("mode")).toUpperCase() : "PATH_EXIST";
         String path = parameters.containsKey("path") ? (String) parameters.get("path") : "";
+        final String folderIgnoreFiles = parameters.containsKey("folderIgnoreFiles") ? (String) parameters.get("folderIgnoreFiles") : "";
+
+
+        SmbFilenameFilter smbFilenameFilter = new SmbFilenameFilter() {
+            @Override
+            public boolean accept(SmbFile smbFile, String s) throws SmbException {
+                return !s.matches(folderIgnoreFiles);
+            }
+        };
 
         Mode enumMode = Mode.PATH_EXIST;
 
                         break;
                     case FOLDER_EMPTY:
                         if (smbFileExists) {
-                            if (smbFile.list().length == 0) {
+                            if (smbFile.list(smbFilenameFilter).length == 0) {
                                 serviceStatus = PollStatus.up();
                             } else {
                                 serviceStatus = PollStatus.down("Directory " + fullUrl + " should be empty but isn't!");
                         break;
                     case FOLDER_NOT_EMPTY:
                         if (smbFileExists) {
-                            if (smbFile.list().length > 0) {
+                            if (smbFile.list(smbFilenameFilter).length > 0) {
                                 serviceStatus = PollStatus.up();
                             } else {
                                 serviceStatus = PollStatus.down("Directory " + fullUrl + " should not be empty but is!");

features/poller/cifs-monitor/src/test/java/org/opennms/netmgt/poller/monitors/JCifsMonitorTest.java

 import jcifs.smb.NtlmPasswordAuthentication;
 import jcifs.smb.SmbException;
 import jcifs.smb.SmbFile;
+import jcifs.smb.SmbFilenameFilter;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
         mockSmbFolderEmpty = createNiceMock(SmbFile.class);
         expect(mockSmbFolderEmpty.exists()).andReturn(true).anyTimes();
-        expect(mockSmbFolderEmpty.list()).andReturn(new String[]{}).anyTimes();
+        expect(mockSmbFolderEmpty.list((SmbFilenameFilter) anyObject())).andReturn(new String[]{}).anyTimes();
         expectNew(SmbFile.class, new Class<?>[]{String.class, NtlmPasswordAuthentication.class}, eq("smb://10.123.123.123/folderEmpty"), isA(NtlmPasswordAuthentication.class)).andReturn(mockSmbFolderEmpty).anyTimes();
 
         mockSmbFolderNotEmpty = createNiceMock(SmbFile.class);
         expect(mockSmbFolderNotEmpty.exists()).andReturn(true).anyTimes();
-        expect(mockSmbFolderNotEmpty.list()).andReturn(new String[]{"1", "2", "3", "4", "5"}).anyTimes();
+        expect(mockSmbFolderNotEmpty.list((SmbFilenameFilter) anyObject())).andReturn(new String[]{"ABCD", "ACBD", "DCBA", "DABC"}).anyTimes();
         expectNew(SmbFile.class, new Class<?>[]{String.class, NtlmPasswordAuthentication.class}, eq("smb://10.123.123.123/folderNotEmpty"), isA(NtlmPasswordAuthentication.class)).andReturn(mockSmbFolderNotEmpty).anyTimes();
 
         mockSmbFileSmbException = createNiceMock(SmbFile.class);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.