Search code examples
ubuntupluginsjmeternagios

Nagios test with jmeter plugin failed with CRITICAL: ... java.util.prefs.FileSystemPreferences$1 run


The issue have been reproduced for a fresh installed and upgraded Lubuntu 20.04 with 5.4.0-42-generic kernel, Nagios 4.4.6, Java 1.8.0_265, Jmeter 5.3.

enter image description here

When run this plugin manually:

user@ubuntu:~$ /usr/bin/perl /usr/local/nagios/libexec/jmeter.pl -j=/usr/local/nagios/share/jmeter -p=/usr/local/nagios/libexec/test.jmx -t 80 -w 90 -c 100
OK :  | sum_time=26.91
user@ubuntu:~$ echo $#
0

Once I've got the same result as on the screenshot above by running the same using sudo, but could not reproduce it again:

$ sudo /usr/bin/perl /usr/local/nagios/libexec/jmeter.pl -j=/usr/local/nagios/share/jmeter -p=/usr/local/nagios/libexec/test.jmx -t 80 -w 90 -c 100
[sudo] password for user: 
CRITICAL: 'java -server  -jar /usr/local/nagios/share/jmeter/bin/ApacheJMeter.jar --nongui --propfile /usr/local/nagios/share/jmeter/bin/jmeter.properties --testfile /usr/local/nagios/libexec/test.jmx --logfile /tmp/1597861570.41537.jtl' exit with wait status of 0 Errors Aug 19, 2020 9:26:21 PM java.util.prefs.FileSystemPreferences$1 run

INFO: Created user preferences directory.

To get more detailed output, I've enabled debugging in nagios.cfg file (debug_level=-1):

[1597866795.863118] [001.0] [pid=44433] handle_async_service_check_result()
[1597866795.863907] [016.0] [pid=44433] ** Handling ACTIVE async check result for service 'Test production jmeter test' on host 'test.company.com' from 'Core Worker 44437'... current state 2 last_hard_state 2 
[1597866795.864002] [016.1] [pid=44433]  * OPTIONS: 0, SCHEDULED: 1, RESCHEDULE: 1, EXITED OK: 1, RETURN CODE: 2, OUTPUT:
CRITICAL: 'java -server  -jar /usr/local/nagios/share/jmeter/bin/ApacheJMeter.jar --nongui --propfile /usr/local/nagios/share/jmeter/bin/jmeter.properties --testfile /usr/local/nagios/libexec/test.jmx --logfile /tmp/1597866748.44494.jtl' exit with wait status of 0 Errors Aug 19, 2020 10:52:34 PM java.util.prefs.FileSystemPreferences$1 run

WARNING: Couldn't create user preferences directory. User preferences are unusable.

Aug 19, 2020 10:52:34 PM java.util.prefs.FileSystemPreferences$1 run

WARNING: java.io.IOException: No such file or directory

Aug 19, 2020 10:53:06 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode

WARNING: Could not lock User prefs.  Unix error code 2.

Aug 19, 2020 10:53:06 PM java.util.prefs.FileSystemPreferences syncWorld

WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.


[1597866795.864097] [001.0] [pid=44433] get_service_check_return_code()
[1597866795.864135] [016.1] [pid=44433] Service is in a non-OK state!
[1597866795.864262] [016.1] [pid=44433] Host is currently UP, so we'll recheck its state to make sure...
[1597866795.864337] [016.1] [pid=44433] Service was NOT OK at last check (CRITICAL).
[1597866795.864374] [016.1] [pid=44433] Service is still in a non-OK state (CRITICAL)!

Solution

  • Googling for

    WARNING: Could not lock User prefs.  Unix error code 2
    

    Which I got by reviewing debug log file (sudo tail -F /usr/local/nagios/var/nagios.debug) I've found out I have been required to create /home/nagios folder:

    $ sudo mkdir /home/nagios
    $ sudo chmod nagios:nagios /home/nagios
    

    After this the next folders have been created in case of nagios service processing:

    root@ubuntu:/home/nagios/.java# ls -ailh
    total 0
    100900054 drwxr-xr-x 4 nagios nagios 44 сер 19 23:23 .
     67258544 drwxr-xr-x 3 nagios nagios 87 сер 19 23:24 ..
     67261722 drwxr-xr-x 2 root   root   52 сер 19 23:23 .systemPrefs
       109430 drwx------ 3 nagios nagios 73 сер 19 23:23 .userPrefs
    

    And nagios started displaying OK status:

    enter image description here

    Reference