Testcases for reading system log
authorArjen Baart <arjen@andromeda.nl>
Mon, 14 Sep 2020 06:08:33 +0000 (08:08 +0200)
committerArjen Baart <arjen@andromeda.nl>
Mon, 14 Sep 2020 06:08:33 +0000 (08:08 +0200)
12 files changed:
src/web/gnucomo.css
test/Makefile.am
test/messages.bad [new file with mode: 0644]
test/read_bad_messages [new file with mode: 0755]
test/read_bad_messages.log.expect [new file with mode: 0644]
test/read_messages
test/read_without_hostname [new file with mode: 0755]
test/t0003.errors [deleted file]
test/t0003.expect [deleted file]
test/t0003.sh [deleted file]
test/t0004.sh [deleted file]
test/vd.messages [deleted file]

index af253a5..6b59b1a 100644 (file)
@@ -149,7 +149,7 @@ img
   top           : 73px;
   bottom        : 20px;
   margin        : 0px 0px 0px 5px;
-  width         : auto;
+  width         : 98%;
   height        : auto;
   padding-left  : 5px;
   padding-right : 12px;
index feb3f55..1f61670 100644 (file)
@@ -1 +1,5 @@
-TESTS = createdb upgradedb read_messages
+TESTS = createdb upgradedb read_messages read_bad_messages read_apache_error read_without_hostname
+
+clean-local:
+       rm -f gcm_input.log log.tbl
+       rm -f dump.latest.sql dump.upgraded.sql
diff --git a/test/messages.bad b/test/messages.bad
new file mode 100644 (file)
index 0000000..504e966
--- /dev/null
@@ -0,0 +1,16 @@
+Jun  4 04:02:08 example1 syslogd 1.4.1: restart.
+Jun  4 08:30:28 example1 sshd(pam_unix)[9380]: session opened for user bob by (uid=0)
+Jun  4 08:32:57 example1 sshd(pam_unix)[9380]: session closed for user bob
+Jun  4 12:43:39 example1 sshd(pam_unix)[9689]: session opened for user alice by (uid=0)
+Jun  4 12:44:51 example1 sshd(pam_unix)[9689]: session closed for user alice
+Jun  4 14:09:04 example1 sshd(pam_unix)[9874]: authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=test.gnucomo.org  user=alice
+nearly empty line
+Jun  4 16:42:44 example1 sshd(pam_unix)[10058]: session closed for user alice
+Jun  5 04:02:16 example1 
+Jun  6 04:02:05 example1 syslogd 1.4.1: restart.
+Jun  6 11:20:31 example1 sshd(pam_unix)[13242]: session opened for user alice by (uid=0)
+Jun  6 11:26:09 example1 sshd(pam_unix)[13242]: session closed for user alice
+Jun  7 04:02:08 example1 syslogd 1.4.1: restart.
+
+Jun  8 04:02:09 example1 syslogd 1.4.1: restart.
+
diff --git a/test/read_bad_messages b/test/read_bad_messages
new file mode 100755 (executable)
index 0000000..0abb454
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+#
+#  Create an object 'example1.gnucomo.test' in the database and
+#  parse a piece of a syslog file with bad, short and empty lines.
+#  There should be warnings printed on the log
+
+rm -f gcm_input.log
+
+createdb gnucomo_test
+
+if psql gnucomo_test -q <../src/database/create.sql >/dev/null
+then
+   psql gnucomo_test -q -c "insert into object (objectname) values ('example1.gnucomo.test')"
+   ../src/gcm_input/gcm_input -c gnucomo_test -h example1.gnucomo.test -d 'Jun 9 2002 20:30:45' <messages.bad
+   psql gnucomo_test -q -t -c "select * from log" -o log.tbl
+   diff read_bad_messages.log.expect gcm_input.log
+   result=$?
+   psql gnucomo_test -f ../src/database/destroy.sql -q
+   dropdb gnucomo_test
+   exit $result
+else
+   echo Can not create test database
+   dropdb gnucomo_test
+   exit 1
+fi
diff --git a/test/read_bad_messages.log.expect b/test/read_bad_messages.log.expect
new file mode 100644 (file)
index 0000000..29d4643
--- /dev/null
@@ -0,0 +1,6 @@
+gcm_input WARNING: Not a valid line: nearly empty line
+Can not insert log element .
+gcm_input WARNING: Not a valid line: Jun  5 04:02:16 example1 
+Can not insert log element .
+Can not insert log element .
+Can not insert log element .
index 36c861e..b18d254 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 #
-#  Create an object 'kithira.andromeda.nl' in the database and
+#  Create an object 'example1.gnucomo.test' in the database and
 #  parse a piece of a syslog file.
 #  This tests normal operation in which gcm_input reads a syslog file
 #  directly.
diff --git a/test/read_without_hostname b/test/read_without_hostname
new file mode 100755 (executable)
index 0000000..de8cb28
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+#
+#  Create an object 'kithira.andromeda.nl' in the database and
+#  try to parse a piece of a syslog file without specifying the hostname.
+#  The message should be rejected on account of an unknown host.
+
+rm -f gcm_input.log
+
+createdb gnucomo_test
+result=1
+
+if psql gnucomo_test -q <../src/database/create.sql >/dev/null
+then
+   psql gnucomo_test -q -c "insert into object (objectname) values ('kithira.andromeda.nl')"
+   ../src/gcm_input/gcm_input -c gnucomo_test  <messages
+   NR_LOGS=`psql gnucomo_test -q -t -c "select count(*) from log"`
+   if [[ $NR_LOGS -eq 0 ]]
+   then
+      echo "No log entries in database"
+      result=0
+   fi
+   if [[ $result -eq 0 ]]
+   then
+      GCM_LOG=`cat gcm_input.log`
+      echo $GCM_LOG
+      if [[ $GCM_LOG != "Can not determine the hostname where the message came from." ]]
+      then
+         result=2
+      fi
+   fi
+   psql gnucomo_test -f ../src/database/destroy.sql -q
+   dropdb gnucomo_test
+   exit $result
+else
+   echo Can not create test database
+   dropdb gnucomo_test
+   exit 1
+fi
diff --git a/test/t0003.errors b/test/t0003.errors
deleted file mode 100644 (file)
index 2dad7c2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "object_abuse_pkey" for table "object_abuse"
-NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "object_statistics_pkey" for table "object_statistics"
-NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "parameter_pkey" for table "parameter"
-NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "parameter_class_pkey" for table "parameter_class"
-NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "parameter_notification_pkey" for table "parameter_notification"
-NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "property_pkey" for table "property"
-NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "service_pattern_pkey" for table "service_pattern"
-ERROR:  role "view" already exists
-ERROR:  role "ops" already exists
-ERROR:  role "admin" already exists
-ERROR:  role "daemon" already exists
-ERROR:  role "gnucomo" already exists
-gcm_input WARNING: Not a valid line: nearly empty line
-gcm_input WARNING: Not a valid line: Jun  5 04:02:16 vd 
diff --git a/test/t0003.expect b/test/t0003.expect
deleted file mode 100644 (file)
index 963611c..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
- objectid |  objectname  | objectcode | scp_enabled | scp_inet | mail_enabled | mail_from | sms_enabled | sms_number | fax_enabled | fax_number | object_description | object_owner | physical_location | timezone | remark | os | os_version | log_count | notification_count | parameter_count 
-----------+--------------+------------+-------------+----------+--------------+-----------+-------------+------------+-------------+------------+--------------------+--------------+-------------------+----------+--------+----+------------+-----------+--------------------+-----------------
-        1 | vd.wt.tno.nl |            |             |          |              |           |             |            |             |            |                    |              |                   |          |        |    |            |           |                    |                
-(1 row)
-
- logid | objectid | original_filename | servicecode |    object_timestamp    |       timestamp        |                                                                     rawdata                                                                      | processed | recognized 
--------+----------+-------------------+-------------+------------------------+------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+-----------+------------
-     1 |        1 |                   | syslogd     | 2002-06-02 04:02:17+02 | 2002-09-05 20:30:45+02 | Jun  2 04:02:17 vd syslogd 1.4.1: restart.                                                                                                       | f         | f
-     2 |        1 |                   | syslogd     | 2002-06-03 04:02:03+02 | 2002-09-05 20:30:45+02 | Jun  3 04:02:03 vd syslogd 1.4.1: restart.                                                                                                       | f         | f
-     3 |        1 |                   | syslogd     | 2002-06-04 04:02:08+02 | 2002-09-05 20:30:45+02 | Jun  4 04:02:08 vd syslogd 1.4.1: restart.                                                                                                       | f         | f
-     4 |        1 |                   | sshd        | 2002-06-04 08:30:28+02 | 2002-09-05 20:30:45+02 | Jun  4 08:30:28 vd sshd(pam_unix)[9380]: session opened for user ebusp by (uid=0)                                                                | f         | f
-     5 |        1 |                   | sshd        | 2002-06-04 08:32:57+02 | 2002-09-05 20:30:45+02 | Jun  4 08:32:57 vd sshd(pam_unix)[9380]: session closed for user ebusp                                                                           | f         | f
-     6 |        1 |                   | sshd        | 2002-06-04 12:39:58+02 | 2002-09-05 20:30:45+02 | Jun  4 12:39:58 vd sshd(pam_unix)[9644]: session opened for user victorsd by (uid=0)                                                             | f         | f
-     7 |        1 |                   | sshd        | 2002-06-04 12:43:39+02 | 2002-09-05 20:30:45+02 | Jun  4 12:43:39 vd sshd(pam_unix)[9689]: session opened for user victorsd by (uid=0)                                                             | f         | f
-     8 |        1 |                   | sshd        | 2002-06-04 12:44:51+02 | 2002-09-05 20:30:45+02 | Jun  4 12:44:51 vd sshd(pam_unix)[9689]: session closed for user victorsd                                                                        | f         | f
-     9 |        1 |                   | sshd        | 2002-06-04 12:45:47+02 | 2002-09-05 20:30:45+02 | Jun  4 12:45:47 vd sshd(pam_unix)[9722]: session opened for user victorsd by (uid=0)                                                             | f         | f
-    10 |        1 |                   | sshd        | 2002-06-04 12:58:26+02 | 2002-09-05 20:30:45+02 | Jun  4 12:58:26 vd sshd(pam_unix)[9722]: session closed for user victorsd                                                                        | f         | f
-    11 |        1 |                   | sshd        | 2002-06-04 14:09:04+02 | 2002-09-05 20:30:45+02 | Jun  4 14:09:04 vd sshd(pam_unix)[9874]: authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=wt4050.wt.tno.nl  user=victorsd | f         | f
-    12 |        1 |                   | sshd        | 2002-06-04 14:09:10+02 | 2002-09-05 20:30:45+02 | Jun  4 14:09:10 vd sshd(pam_unix)[9874]: session opened for user victorsd by (uid=0)                                                             | f         | f
-    13 |        1 |                   | sshd        | 2002-06-04 14:25:08+02 | 2002-09-05 20:30:45+02 | Jun  4 14:25:08 vd sshd(pam_unix)[9644]: session closed for user victorsd                                                                        | f         | f
-    14 |        1 |                   | sshd        | 2002-06-04 15:10:25+02 | 2002-09-05 20:30:45+02 | Jun  4 15:10:25 vd sshd(pam_unix)[9874]: session closed for user victorsd                                                                        | f         | f
-    15 |        1 |                   | sshd        | 2002-06-04 16:40:52+02 | 2002-09-05 20:30:45+02 | Jun  4 16:40:52 vd sshd(pam_unix)[10056]: session opened for user arjen by (uid=0)                                                               | f         | f
-    16 |        1 |                   | sshd        | 2002-06-04 16:40:53+02 | 2002-09-05 20:30:45+02 | Jun  4 16:40:53 vd sshd(pam_unix)[10056]: session closed for user arjen                                                                          | f         | f
-    17 |        1 |                   | sshd        | 2002-06-04 16:41:04+02 | 2002-09-05 20:30:45+02 | Jun  4 16:41:04 vd sshd(pam_unix)[10058]: session opened for user arjen by (uid=0)                                                               | f         | f
-    18 |        1 |                   | su          | 2002-06-04 16:42:01+02 | 2002-09-05 20:30:45+02 | Jun  4 16:42:01 vd su(pam_unix)[10090]: session opened for user root by arjen(uid=504)                                                           | f         | f
-    19 |        1 |                   | su          | 2002-06-04 16:42:42+02 | 2002-09-05 20:30:45+02 | Jun  4 16:42:42 vd su(pam_unix)[10090]: session closed for user root                                                                             | f         | f
-    20 |        1 |                   | sshd        | 2002-06-04 16:42:44+02 | 2002-09-05 20:30:45+02 | Jun  4 16:42:44 vd sshd(pam_unix)[10058]: session closed for user arjen                                                                          | f         | f
-    21 |        1 |                   | syslogd     | 2002-06-06 04:02:05+02 | 2002-09-05 20:30:45+02 | Jun  6 04:02:05 vd syslogd 1.4.1: restart.                                                                                                       | f         | f
-    22 |        1 |                   | sshd        | 2002-06-06 09:22:44+02 | 2002-09-05 20:30:45+02 | Jun  6 09:22:44 vd sshd(pam_unix)[13090]: session opened for user ebusp by (uid=0)                                                               | f         | f
-    23 |        1 |                   | sshd        | 2002-06-06 09:25:32+02 | 2002-09-05 20:30:45+02 | Jun  6 09:25:32 vd sshd(pam_unix)[13090]: session closed for user ebusp                                                                          | f         | f
-    24 |        1 |                   | sshd        | 2002-06-06 11:20:31+02 | 2002-09-05 20:30:45+02 | Jun  6 11:20:31 vd sshd(pam_unix)[13242]: session opened for user verhoeff by (uid=0)                                                            | f         | f
-    25 |        1 |                   | sshd        | 2002-06-06 11:26:09+02 | 2002-09-05 20:30:45+02 | Jun  6 11:26:09 vd sshd(pam_unix)[13242]: session closed for user verhoeff                                                                       | f         | f
-    26 |        1 |                   | syslogd     | 2002-06-07 04:02:08+02 | 2002-09-05 20:30:45+02 | Jun  7 04:02:08 vd syslogd 1.4.1: restart.                                                                                                       | f         | f
-    27 |        1 |                   | syslogd     | 2002-06-08 04:02:09+02 | 2002-09-05 20:30:45+02 | Jun  8 04:02:09 vd syslogd 1.4.1: restart.                                                                                                       | f         | f
-(27 rows)
-
diff --git a/test/t0003.sh b/test/t0003.sh
deleted file mode 100644 (file)
index bdb2e60..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/sh
-
-#
-#  Create an object 'vd.wt.tno.nl' in the database and
-#  parse a piece of a syslog file with short and even empty lines.
-#  There should be warnings printed on stderr.
-#
-
-LD_LIBRARY_PATH=/usr/local/pqxx/lib
-export LD_LIBRARY_PATH
-
-cd ..
-
-if psql gnucomo_test -q <src/database/create.sql >/dev/null
-then
-   psql gnucomo_test -q -c "insert into object (objectname) values ('vd.wt.tno.nl')"
-   psql gnucomo_test -c "select * from object"
-   src/gcm_input/gcm_input -c gnucomo_test -h vd.wt.tno.nl -d 'sep 5 2002 20:30:45' <test/vd.messages
-   psql gnucomo_test -c "select * from log"
-   psql gnucomo_test -f src/database/destroy.sql -q
-   exit $result
-else
-   echo Can not create test database
-   exit 1
-fi
diff --git a/test/t0004.sh b/test/t0004.sh
deleted file mode 100644 (file)
index db09dd2..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-
-#
-#  Create an object 'kithira.andromeda.nl' in the database and
-#  try to parse a piece of a syslog file without specifying the hostname.
-#  The message should be rejected on account of an unknown host.
-
-cd ..
-
-if psql gnucomo_test -q <src/database/create.sql >/dev/null
-then
-   psql gnucomo_test -q -c "insert into object (objectname) values ('kithira.andromeda.nl')"
-   psql gnucomo_test -c "select * from object"
-   src/gcm_input/gcm_input -c gnucomo_test  <test/messages
-   psql gnucomo_test -c "select * from log"
-   psql gnucomo_test -f src/database/destroy.sql -q
-   exit $result
-else
-   echo Can not create test database
-   exit 1
-fi
diff --git a/test/vd.messages b/test/vd.messages
deleted file mode 100644 (file)
index 5f56296..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-Jun  2 04:02:17 vd syslogd 1.4.1: restart.
-Jun  3 04:02:03 vd syslogd 1.4.1: restart.
-Jun  4 04:02:08 vd syslogd 1.4.1: restart.
-Jun  4 08:30:28 vd sshd(pam_unix)[9380]: session opened for user ebusp by (uid=0)
-Jun  4 08:32:57 vd sshd(pam_unix)[9380]: session closed for user ebusp
-Jun  4 12:39:58 vd sshd(pam_unix)[9644]: session opened for user victorsd by (uid=0)
-Jun  4 12:43:39 vd sshd(pam_unix)[9689]: session opened for user victorsd by (uid=0)
-Jun  4 12:44:51 vd sshd(pam_unix)[9689]: session closed for user victorsd
-Jun  4 12:45:47 vd sshd(pam_unix)[9722]: session opened for user victorsd by (uid=0)
-Jun  4 12:58:26 vd sshd(pam_unix)[9722]: session closed for user victorsd
-Jun  4 14:09:04 vd sshd(pam_unix)[9874]: authentication failure; logname= uid=0 euid=0 tty=NODEVssh ruser= rhost=wt4050.wt.tno.nl  user=victorsd
-Jun  4 14:09:10 vd sshd(pam_unix)[9874]: session opened for user victorsd by (uid=0)
-Jun  4 14:25:08 vd sshd(pam_unix)[9644]: session closed for user victorsd
-Jun  4 15:10:25 vd sshd(pam_unix)[9874]: session closed for user victorsd
-Jun  4 16:40:52 vd sshd(pam_unix)[10056]: session opened for user arjen by (uid=0)
-Jun  4 16:40:53 vd sshd(pam_unix)[10056]: session closed for user arjen
-Jun  4 16:41:04 vd sshd(pam_unix)[10058]: session opened for user arjen by (uid=0)
-nearly empty line
-Jun  4 16:42:01 vd su(pam_unix)[10090]: session opened for user root by arjen(uid=504)
-Jun  4 16:42:42 vd su(pam_unix)[10090]: session closed for user root
-Jun  4 16:42:44 vd sshd(pam_unix)[10058]: session closed for user arjen
-Jun  5 04:02:16 vd 
-Jun  6 04:02:05 vd syslogd 1.4.1: restart.
-Jun  6 09:22:44 vd sshd(pam_unix)[13090]: session opened for user ebusp by (uid=0)
-Jun  6 09:25:32 vd sshd(pam_unix)[13090]: session closed for user ebusp
-Jun  6 11:20:31 vd sshd(pam_unix)[13242]: session opened for user verhoeff by (uid=0)
-Jun  6 11:26:09 vd sshd(pam_unix)[13242]: session closed for user verhoeff
-Jun  7 04:02:08 vd syslogd 1.4.1: restart.
-Jun  8 04:02:09 vd syslogd 1.4.1: restart.
-