Пример #1
0
int main(int argc, char *argv[]) {

	int getopts;
	char filename[1000];
	char *app;
	int priority;
	char *event;
	char *description;
	char apikey[48];
	int verbose = 0;
	int getopt_index = 0;

	static struct option long_options[] =
	{
		{"apifile",	required_argument,	0, 'f'},
		{"app",		required_argument,	0, 'a'},
		{"priority",	required_argument,	0, 'p'},
		{"event",	required_argument,	0, 'e'},
		{"description",	required_argument,	0, 'd'},
		{"verbose",	no_argument,		0, 'v'},
		{"help",	no_argument,		0, 'h'}
	};

	while (( getopts = getopt_long(argc, argv, "f:a:p:e:d:vh", long_options, &getopt_index)) != -1)
	{
		switch (getopts)
		{
			case 'h':
				usage(argv[0]);
				exit(1);
			case 'v':
				verbose = 1;
				break;
			case 'f':
				strncpy(filename, optarg, sizeof(filename));
				break;
			case 'a':
				app = optarg;
				break;
			case 'p':
				priority = atoi(optarg);
				break;
			case 'e':
				event = optarg;
				break;
			case 'd':
				description = optarg;
				break;
			default:
				usage(argv[0]);
				exit(1);
		}
	}

	if ( (filename == NULL) || (app == NULL) || (event == NULL) ||
		       (description == NULL) || (priority < -2) || (priority > 2))
	{
		usage(argv[0]);
		exit(1);
	}

	if ( verbose > 0 )
	{
		printf("filename: %s\n", filename);
		printf("app: %s\n", app);
		printf("priority: %i\n", priority);
		printf("event: %s\n", event);
		printf("description: %s\n", description);
	}

	FILE *fp;
	if (( fp=fopen(filename, "r")) == NULL)
	{
		printf("Unable to open config file: %s\n", filename);
		return 1;
	}
	else
	{
		if ( fscanf(fp, "apikey = %s", &apikey) == 1 )
		{
			if ( verbose > 0 )
			{
				printf("apikey: %s\n", apikey);
				printf("Return code: %d\n", nma_push_msg(apikey, priority, app, event, description));
				return 0;
			}
			else
			{
				nma_push_msg(apikey, priority, app, event, description);
				return 0;
			}
		}
		else
		{
			printf("Invalid syntax config file: %s\n", filename);
			return 1;
		}
	}
	fclose(fp);
}
Пример #2
0
bool notifymyandroid(char* api_key, const char* time) {
	return nma_push_msg(api_key, 1,"Raspsurveillance", "Intruder detected", "Intruder detected ") == 200;
}