Built a custom plugin; issues with returned status codes

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Built a custom plugin; issues with returned status codes

Post by tmcdonald »

pamplifier wrote:One question, I just realized that I need root privileges to access the logs in /var/log/. I didn't notice because I'm almost always running as root on my test machine. Could the seg fault be due to the fact that the nagios user is trying to access the logfiles when it doesn't have permission to?
I would say so, yes:

Code: Select all

nagios@localhost: /tmp
$ ls -l check_thing somelog
-rwxr-xr-x 1 root root 11725 Jul 24 11:38 check_thing
-rwx------ 1 root root    64 Jul 24 11:45 somelog
nagios@localhost: /tmp
$ ./check_thing -F somelog -w 5 -e 10
Segmentation fault
nagios@localhost: /tmp
$
I did this for you:

Code: Select all

       FILE* logfile = fopen(logpath, "r");
       if (logfile == NULL) {
            printf("CHECK YOUR PERMS!\n");
            return 1;
       }
       fseek(logfile, loffset, SEEK_SET);
       fseek(thingfile, moffset, SEEK_SET);
Always check your pointers ;)
pamplifier wrote:Right now I'm looking up ways to ameliorate this, including how Nagios' does it with its pre-existing plugins in /plugins-root. I'm thinking of adding a new rule to /etc/sudoers, is that the best solution for this?
That's probably the "right way" to do this. I would need to look over the code for the plugins that do this though to find out for sure how they work.
Former Nagios employee
Locked