diff --git a/nbs/__init__.py b/nbs/__init__.py
index 689d7de..d4162c9 100644
--- a/nbs/__init__.py
+++ b/nbs/__init__.py
@@ -5,12 +5,8 @@
class NetBoxScanner(object):
- def __init__(self, netbox, hosts, tag, cleanup):
- self.netbox = api(
- netbox['address'],
- netbox['token'],
- ssl_verify=netbox.getboolean('tls_verify')
- )
+ def __init__(self, address, token, tls_verify, hosts, tag, cleanup):
+ self.netbox = api(address, token, ssl_verify=tls_verify)
self.hosts = hosts
self.tag = tag
self.cleanup = cleanup
diff --git a/netbox-scanner.py b/netbox-scanner.py
index 0f4606f..b3d046b 100644
--- a/netbox-scanner.py
+++ b/netbox-scanner.py
@@ -53,7 +53,9 @@ def cmd_nmap(): # nmap handler
h = Nmap(nmap['path'], nmap['unknown'])
h.run()
scan = NetBoxScanner(
- netbox,
+ netbox['address'],
+ netbox['token'],
+ netbox.getboolean('tls_verify'),
h.hosts,
nmap['tag'],
nmap.getboolean('cleanup')
diff --git a/samples/nmap-1.xml b/samples/nmap-1.xml
new file mode 100644
index 0000000..df7ecb0
--- /dev/null
+++ b/samples/nmap-1.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ cpe:/a:openbsd:openssh:5.3p1
+ cpe:/o:linux:kernel
+
+
+
+
+
+
+ cpe:/a:apache:http_server:2.2.14
+
+
+
+
+
+
+
+
+
+ cpe:/o:linux:linux_kernel:2.6.39
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/nmap-2.xml b/samples/nmap-2.xml
new file mode 100644
index 0000000..5e689e8
--- /dev/null
+++ b/samples/nmap-2.xml
@@ -0,0 +1,480 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100644
index 0000000..576e523
--- /dev/null
+++ b/tests/run_tests.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# Before running these tests, you must define some
+# environment variables, such as:
+#
+# $ export NETBOX_ADDRESS="https..."
+# $ export NETBOX_TOKEN="..."
+# $ export NMAP_PATH="..."
+##
+
+python -m unittest tests.test_netbox
+python -m unittest tests.test_nmap
diff --git a/tests/test_netbox.py b/tests/test_netbox.py
new file mode 100644
index 0000000..0ed5f43
--- /dev/null
+++ b/tests/test_netbox.py
@@ -0,0 +1,17 @@
+import unittest
+from os import environ
+from nbs import NetBoxScanner
+
+
+class TestRequest(unittest.TestCase):
+ def test_api(self):
+ address = environ.get('NETBOX_ADDRESS')
+ token = environ.get('NETBOX_TOKEN')
+
+ netbox = NetBoxScanner(address, token, False, [], 'test', False)
+ self.assertIsInstance(netbox, NetBoxScanner)
+ self.assertEqual(netbox.sync(), True)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/test_nmap.py b/tests/test_nmap.py
new file mode 100644
index 0000000..3a1e4fd
--- /dev/null
+++ b/tests/test_nmap.py
@@ -0,0 +1,17 @@
+import unittest
+from os import environ
+from nbs.nmap import Nmap
+
+
+class TestRequest(unittest.TestCase):
+ def test_api(self):
+ path = environ.get('NMAP_PATH')
+
+ nmap = Nmap(path, 'test')
+ self.assertIsInstance(nmap, Nmap)
+ nmap.run()
+ self.assertIsInstance(nmap.hosts, list)
+
+
+if __name__ == '__main__':
+ unittest.main()