file existence check
    Andreas Ericsson 
    ae at op5.se
       
    Thu Jul  8 02:31:16 CEST 2004
    
    
  
Neil wrote:
> Hey guys,
> I would like to monitor if a file gets uploaded successfully by our 
> customer every night at 10pm. Filename syntax is 
> Upload_Daily_20040707.txt. Programatically, I can extract the current 
> date in my nagios system and have the date get appended to the syntax. 
> So if file exists after 10pm check, it becomes OK. If not, it will 
> remain RED. My concern is that after 12midnight, it won't be checked 
> anymore because date will change. But I can create 2 checks, one for 
> today and the other one for yesterday.
> I would like to know guys how you would implement it and what you think 
> about my approach.
Do something like this, and pass the exact filename as the first 
argument. It's a quick-hack (written in the mailer window), but it 
should be enough to get you started, and it probably compiles on any 
posix-compliant system. If you want to specify threshold values and such 
you'll have to add it yourself.
--[ cut here ]---
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
int main(int argc, char **argv)
{
	time_t now;
	int fd;
	struct stat fs;
	int status = 0;
	if(argc != 2) {
		printf("usage: %s <filename>\n", argv[0]);
		exit(3);
	}
	now = time(NULL);
	fd = open(argv[0], O_RDONLY);
	if(fd == -1) {
		printf("Unable to open %s for reading.\n", argv[1]);
		exit(1);
	}
	fstat(fd, &fs);
	if(now > fs.st_mtime + (24 * 3600)) status = 1;
	printf("%s was last modified %u seconds ago.\n",
		now - fs.st_mtime);
	return(status);
}
--[ and here ]---
In case anyone's lawyer is wondering, that code up there is in the 
public domain with no restrictions what so ever, so abuse it any way you 
want.
> Thanks.
You're welcome.
> Neil
> 
-- 
Sourcerer / Andreas Ericsson
OP5 AB
+46 (0)733 709032
andreas.ericsson at op5.se
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null
    
    
More information about the Users
mailing list