/*
** SellaNMS
** $Id: check.cxx,v 1.12 2008/01/31 22:31:11 sella Exp $
** Copyright (c) 2001-2005 Digital Genesis Software, LLC. All Rights Reserved.
** Released under the GPL Version 2 License.
** http://www.digitalgenesis.com
*/

static const char rcsid[] = "$Id: check.cxx,v 1.12 2008/01/31 22:31:11 sella Exp $";

#include "check.h"
#include <stdio.h>

void getLibrary(int &library) {
	library = LIBRARY_STORAGE;
}

void check(RESULT &result, ConfigNode *config) {
	const int table_count = 24;

	Storage storage;
	StorageData data;

	char buf[132];
	char tables[table_count][64] = {
		"link",
		"link_data",
		"link_point",
		"output",
		"gui_event",
		"gui_history",
		"gui_event_message",
		"discovery_icmp",
		"discovery_snmp_oid",
		"gui_view",
		"gui_channel_assoc",
		"gui_channel",
		"gui_user",
		"gui_user_prefs",
		"element",
		"element_data",
		"element_attr",
		"interface",
		"interface_data",
		"interface_attr",
		"ip",
		"ip_data",
		"ip_attr"
	};

	if ((result = storage.setConfig(*config)) == SUCCESS) {
		for (int x = 0; x < table_count; x++) {
			snprintf(buf, 132, "SELECT COUNT(*) FROM %s", tables[x]);
			if ((result = storage.query(data, buf)) != SUCCESS) {
				LMSG("ERROR: Table %s is missing from the database.", tables[x]);
				return;
			}
		}
	}
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim:
** vim: noet ts=3 sw=3
*/
