Exemple #1
0
int lua::core_wrapper::simple_query(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	try {
		std::list<std::string> arguments;
		int arg_count = lua_instance.size();
		if (arg_count < 2)
			return lua_instance.error("Incorrect syntax: simple_query(command, args)");
		if (lua_instance.is_table()) {
			std::list<std::string> table = lua_instance.pop_array();
			arguments.insert(arguments.begin(), table.begin(), table.end());
		} else {
			arguments.push_front(lua_instance.pop_string());
		}
		std::string command = lua_instance.pop_string();
		std::string message;
		std::string perf;
		NSCAPI::nagiosReturn ret = get()->simple_query(command, arguments, message, perf);
		lua_instance.push_code(ret);
		lua_instance.push_string(message);
		lua_instance.push_string(perf);
		return lua_instance.size();
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
}
Exemple #2
0
int check_mk::check_mk_section_wrapper::add_line(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	if (lua_instance.size() < 1)
		return lua_instance.error("Invalid syntax: get_section(s)");
	if (lua_instance.is_string()) {
		try {
			std::string l = lua_instance.pop_string();
			section.add_line(check_mk::packet::section::line(l));
			return 0;
		} catch (const std::exception &e) {
			return lua_instance.error(std::string("Failed to get section: ") + e.what());
		}
	} else {
		check_mk_line_wrapper *obj = Luna<check_mk_line_wrapper>::check(lua_instance, 0);
		if (!obj) {
			return 0;
		}
		try {
			section.add_line(obj->line);
			return 0;
		} catch (const std::exception &e) {
			return lua_instance.error(std::string("Failed to get section: ") + e.what());
		}
	}
}
Exemple #3
0
int lua::core_wrapper::reload(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	if (lua_instance.size() < 1)
		return lua_instance.error("Incorrect syntax: reload([<module>]);");
	std::string module = "module";
	get()->reload(lua_instance.pop_string());
	return 0;
}
Exemple #4
0
static int log_any(lua_State *L, int mode) {
	lua::lua_wrapper lua_instance(L);
	lua::lua_wrapper::stack_trace trace = lua_instance.get_stack_trace();
	if (lua_instance.size() < 1)
		return lua_instance.error("Invalid syntax: log(message)");
	std::string str = lua_instance.pop_string();
	GET_CORE()->log(mode, trace.first, trace.second, str);
	return 0;
}
Exemple #5
0
int check_mk::check_mk_line_wrapper::add_item(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	std::string l;
	if (!lua_instance.pop_string(l)) {
		return lua_instance.error("Invalid syntax: add_item(line)");
	}
	line.items.push_back(l);
	return 0;
}
Exemple #6
0
int check_mk::check_mk_line_wrapper::set_line(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	std::string l;
	if (!lua_instance.pop_string(l)) {
		return lua_instance.error("Invalid syntax: set_line(line)");
	}
	line.set_line(l);
	return 0;
}
Exemple #7
0
int check_mk::check_mk_section_wrapper::set_title(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	std::string title;
	if (!lua_instance.pop_string(title)) {
		return lua_instance.error("Invalid syntax: set_title(title)");
	}
	section.title = title;
	return 1;
}
Exemple #8
0
void lua::lua_runtime::load(scripts::script_information<lua_traits> *info) {
	std::string base_path = info->user_data.base_path_;
	lua::lua_wrapper lua_instance(info->user_data.L);
	lua_instance.set_userdata(lua::lua_traits::user_data_tag, info);
	lua_instance.openlibs();
	lua::lua_script::luaopen(info->user_data.L);
	BOOST_FOREACH(lua::lua_runtime_plugin_type &plugin, plugins) {
		plugin->load(lua_instance);
	}
Exemple #9
0
int lua::core_wrapper::log(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	// log([level], message)
	if (lua_instance.size() < 2)
		return lua_instance.error("Incorrect syntax: log(<level>, <message>);");
	std::string message = lua_instance.pop_string();
	std::string level = lua_instance.pop_string();
	get()->log(nscapi::logging::parse(level), __FILE__, __LINE__, message);
	return 0;
}
Exemple #10
0
int lua::registry_wrapper::simple_subscription(lua_State *L) {
	std::string command, description;
	lua::lua_traits::function fundata;
	lua_wrapper lua_instance(L);
	boost::optional<int> error = read_registration(lua_instance, command, fundata, description);
	if (error)
		return *error;
	info->register_command("simple_submit", command, description, fundata);
	return lua_instance.size();
}
Exemple #11
0
int lua::settings_wrapper::save(lua_State *L) {
	lua_wrapper lua_instance(L);
	if (info == NULL)
		return lua_instance.error("Invalid core");
	try {
		get()->save();
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
	return lua_instance.size();
}
Exemple #12
0
int check_mk::check_mk_line_wrapper::get_item(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	if (lua_instance.size() < 1)
		return lua_instance.error("Invalid syntax: get_line(id)");
	int id = lua_instance.pop_int()-1;
	try {
		std::string item = line.get_item(id);
		lua_instance.push_string(item);
		return 1;
	} catch (const std::exception &e) {
		return lua_instance.error(std::string("Failed to get item: ") + e.what());
	}
}
Exemple #13
0
int lua::settings_wrapper::register_path(lua_State *L) {
	lua_wrapper lua_instance(L);
	if (lua_instance.size() < 3)
		return lua_instance.error("Invalid syntax: register_path(path, title, description)");
	std::string description = lua_instance.pop_string();
	std::string title = lua_instance.pop_string();
	std::string path = lua_instance.pop_string();
	try {
		get()->register_path(path, title, description, false);
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
	return lua_instance.size();
}
Exemple #14
0
int check_mk::check_mk_packet_wrapper::get_section(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	if (lua_instance.size() < 1)
		return lua_instance.error("Invalid syntax: get_section(id)");
	int id = lua_instance.pop_int()-1;
	try {
		check_mk::packet::section s = packet.get_section(id);
		check_mk_section_wrapper* obj = Luna<check_mk_section_wrapper>::createNew(lua_instance);
		obj->section = s;
		return 1;
	} catch (const std::exception &e) {
		return lua_instance.error(std::string("Failed to get section: ") + e.what());
	}
}
Exemple #15
0
int lua::core_wrapper::query(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	try {
		if (lua_instance.size() < 1)
			return lua_instance.error("Incorrect syntax: query(data)");
		std::string data = lua_instance.pop_string();
		std::string response;
		lua_instance.push_boolean(get()->query(data, response));
		lua_instance.push_raw_string(response);
		return 2;
	} catch (...) {
		return lua_instance.error("Unknown exception in: simple_query");
	}
}
Exemple #16
0
int lua::registry_wrapper::register_simple_function(lua_State *L) {
	// void = (cmd, function, desc)
	std::string command, description;
	lua::lua_traits::function fundata;
	lua_wrapper lua_instance(L);
	boost::optional<int> error = read_registration(lua_instance, command, fundata, description);
	if (error)
		return *error;

	if (description.empty())
		description = "Lua script: " + command;
	info->register_command(scripts::nscp::tags::simple_query_tag, command, description, fundata);
	return lua_instance.size();
}
Exemple #17
0
int lua::settings_wrapper::get_section(lua_State *L) {
	lua_wrapper lua_instance(L);
	if (info == NULL)
		return lua_instance.error("Invalid core");
	if (lua_instance.size() < 1)
		return lua_instance.error("Invalid syntax: get_section([section])");

	std::string v = lua_instance.pop_string();
	try {
		lua_instance.push_array(get()->get_section(v));
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
	return lua_instance.size();
}
Exemple #18
0
int check_mk::check_mk_packet_wrapper::add_section(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	if (lua_instance.size() < 1)
		return lua_instance.error("Invalid syntax: get_section(s)");
	check_mk_section_wrapper *obj = Luna<check_mk_section_wrapper>::check(lua_instance, 0);
	if (!obj) {
		return 0;
	}
	try {
		packet.add_section(obj->section);
		return 0;
	} catch (const std::exception &e) {
		return lua_instance.error(std::string("Failed to get section: ") + e.what());
	}
}
Exemple #19
0
int lua::settings_wrapper::set_int(lua_State *L) {
	lua_wrapper lua_instance(L);
	if (info == NULL)
		return lua_instance.error("Invalid core");
	if (lua_instance.size() < 3)
		return lua_instance.error("Invalid syntax: set_int(section, key, value)");
	int v = lua_instance.pop_int();
	std::string k = lua_instance.pop_string();
	std::string s = lua_instance.pop_string();
	try {
		get()->set_int(s, k, v);
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
	return lua_instance.size();
}
Exemple #20
0
int lua::settings_wrapper::get_bool(lua_State *L) {
	lua_wrapper lua_instance(L);
	if (info == NULL)
		return lua_instance.error("Invalid core");
	if (lua_instance.size() < 3)
		return lua_instance.error("Invalid syntax: get_bool(section, key, [value])");
	bool v = lua_instance.pop_boolean();
	std::string k = lua_instance.pop_string();
	std::string s = lua_instance.pop_string();
	try {
		lua_instance.push_boolean(get()->get_int(s, k, v ? 1 : 0) == 1);
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
	return lua_instance.size();
}
Exemple #21
0
int lua::core_wrapper::simple_exec(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	try {
		if (lua_instance.size() < 3)
			return lua_instance.error("Incorrect syntax: simple_exec(target, command, arguments)");
		std::list<std::string> arguments = lua_instance.pop_array();
		std::string command = lua_instance.pop_string();
		std::string target = lua_instance.pop_string();
		std::list<std::string> result;
		NSCAPI::nagiosReturn ret = get()->exec_simple_command(target, command, arguments, result);
		lua_instance.push_code(ret);
		lua_instance.push_array(result);
		return lua_instance.size();
	} catch (...) {
		return lua_instance.error("Unknown exception in: simple_query");
	}
}
Exemple #22
0
int lua::settings_wrapper::register_key(lua_State *L) {
	lua_wrapper lua_instance(L);

	if (lua_instance.size() < 5)
		return lua_instance.error("Invalid syntax: register_key(path, key, type, title, description, default)");
	std::string defaultValue = lua_instance.pop_string();
	std::string description = lua_instance.pop_string();
	std::string title = lua_instance.pop_string();
	std::string type = lua_instance.pop_string();
	std::string key = lua_instance.pop_string();
	std::string path = lua_instance.pop_string();
	try {
		get()->register_key(path, key, type, title, description, defaultValue);
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
	return lua_instance.size();
}
Exemple #23
0
int lua::core_wrapper::simple_submit(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	try {
		if (lua_instance.size() < 5)
			return lua_instance.error("Incorrect syntax: simple_submit(channel, command, code, message, perf)");
		std::string perf = lua_instance.pop_string();
		std::string message = lua_instance.pop_string();
		NSCAPI::nagiosReturn code = lua_instance.pop_code();
		std::string command = lua_instance.pop_string();
		std::string channel = lua_instance.pop_string();
		std::string result;
		NSCAPI::nagiosReturn ret = get()->submit_simple_message(channel, command, code, message, perf, result);
		lua_instance.push_code(ret);
		lua_instance.push_string(result);
		return lua_instance.size();
	} catch (...) {
		return lua_instance.error("Unknown exception in: simple_query");
	}
}
Exemple #24
0
int check_mk::check_mk_lua_wrapper::client_callback(lua_State *L) {
	// void = (function)
	lua::lua_traits::function fundata;
	lua::lua_wrapper lua_instance(L);
	int count = lua_instance.size();
	if (count < 1)
		return lua_instance.error("Invalid syntax: client(<function>);");
	std::string funname;
	if (lua_instance.pop_string(funname)) {
		lua_instance.getglobal(funname);
	}
	if (!lua_instance.pop_function_ref(fundata.function_ref))
		return lua_instance.error("Invalid function");
	if (count > 1) {
		if (!lua_instance.pop_instance_ref(fundata.object_ref))
			return lua_instance.error("Invalid object");
	}
	info->register_command("check_mk", "c_callback", "", fundata);
	return lua_instance.size();
}
Exemple #25
0
int lua::core_wrapper::create_pb_query(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	try {
		std::list<std::string> arguments;
		int arg_count = lua_instance.size();
		if (arg_count < 2)
			return lua_instance.error("Incorrect syntax: create_pb_query(command, args)");
		if (lua_instance.is_table()) {
			std::list<std::string> table = lua_instance.pop_array();
			arguments.insert(arguments.begin(), table.begin(), table.end());
		} else {
			arguments.push_front(lua_instance.pop_string());
		}
		std::string command = lua_instance.pop_string();
		std::string buffer;
		nscapi::protobuf::functions::create_simple_query_request(command, arguments, buffer);
		lua_instance.push_raw_string(buffer);
		return 1;
	} catch (...) {
		return lua_instance.error("Unknown exception");
	}
}
Exemple #26
0
int check_mk::check_mk_line_wrapper::get_line(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	lua_instance.push_string(line.get_line());
	return 1;
}
Exemple #27
0
int check_mk::check_mk_line_wrapper::size_item(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	lua_instance.push_int(line.items.size());
	return 1;
}
Exemple #28
0
static int lua_sleep(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	int time = lua_instance.pop_int();
	boost::this_thread::sleep(boost::posix_time::milliseconds(time));
	return 0;
}
Exemple #29
0
int lua::core_wrapper::submit(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	NSC_LOG_ERROR_STD("Unsupported API called: submit");
	return lua_instance.error("Unsupported API called: submit");
}
Exemple #30
0
int lua::registry_wrapper::subscription(lua_State *L) {
	lua::lua_wrapper lua_instance(L);
	NSC_LOG_ERROR_STD("Unsupported API called: exec");
	return lua_instance.error("Unsupported API called: exec");
}