update with new paths etc

This commit is contained in:
Justin Hammond 2015-10-23 16:02:09 +08:00
parent 6f28b1370e
commit f389e8d073
6 changed files with 174 additions and 18 deletions

View file

@ -42,7 +42,7 @@ endif()
endif()
find_package(Boost REQUIRED COMPONENTS thread filesystem)
find_package(Boost REQUIRED COMPONENTS thread filesystem program_options)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(LMBd -pthread ${Boost_LIBRARIES})

7
dist/LMBd.spec vendored
View file

@ -5,7 +5,7 @@ URL: https://github.com/Fishwaldo/LEDMessageBoard
License: GPL
Version: 1.0.1445180435.6a453c9
Release: 0
BuildRequires: gcc-c++ cmake boost-devel boost-thread boost-filesystem
BuildRequires: gcc-c++ cmake boost-devel boost-thread boost-filesystem boost-program-options
Source0: LMBd-%{version}.tar.gz
@ -24,7 +24,8 @@ make %{?_smp_mflags}
%install
make install DESTDIR=${RPM_BUILD_ROOT} && cd ..
mkdir /var/spool/LMBd
mkdir /var/log/LMBd
%files
%defattr(-,root,root,-)
@ -32,6 +33,8 @@ make install DESTDIR=${RPM_BUILD_ROOT} && cd ..
%{_prefix}/bin/zabbix_stats.py
%config /etc/LMBd.conf
%config /etc/zabbix_stats.cfg
%dir /var/spool/LMBd
%dir /var/log/LMBd
#%doc README
#%config /etc/ozwwebapp/*

View file

@ -91,7 +91,7 @@ namespace LMB {
time.hour, time.minute, time.second, time.ms,
aChannelPtr->getName().c_str(), Log::toString(aLog.getSeverity()),
(aLog.getStream()).str().c_str());
fflush(stdout);
fflush(mpFile);
mSize += nbWritten;
}

View file

@ -136,6 +136,23 @@ int cmd_show_startupmsgs(struct cli_def *cli, const char *command, char *argv[],
return CLI_OK;
}
int cmd_show_logfiledir(struct cli_def *cli, const char *command, char *argv[], int argc)
{
struct LMBCTX *lmbctx = (struct LMBCTX *)cli_get_context(cli);
boost::unique_lock<boost::mutex> scoped_lock(lmbctx->io_mutex);
cli_print(cli, "logfiledir set to %s", lmbctx->logpath.c_str());
return CLI_OK;
}
int cmd_show_monitorpath(struct cli_def *cli, const char *command, char *argv[], int argc)
{
struct LMBCTX *lmbctx = (struct LMBCTX *)cli_get_context(cli);
boost::unique_lock<boost::mutex> scoped_lock(lmbctx->io_mutex);
cli_print(cli, "monitorpath set to %s", lmbctx->monitorpath.c_str());
return CLI_OK;
}
int cmd_set(struct cli_def *cli, const char *command, char *argv[], int argc)
{
@ -190,9 +207,64 @@ int cmd_set_startupmsg(struct cli_def *cli, UNUSED(const char *command), char *a
}
lmbctx->startupmsg[atoi(argv[0])] = std::string(argv[1]);
cli_print(cli, "Startup Message %d set to %s", atoi(argv[0]), argv[1]);
return CLI_OK;
}
int cmd_set_logfiledir(struct cli_def *cli, UNUSED(const char *command), char *argv[],
int argc)
{
if (argc < 1) {
cli_print(cli, "usage: set logfiledir <dir>");
return CLI_OK;
}
struct LMBCTX *lmbctx = (struct LMBCTX *)cli_get_context(cli);
boost::unique_lock<boost::mutex> scoped_lock(lmbctx->io_mutex);
boost::filesystem::path dir(argv[0]);
if (!boost::filesystem::exists(dir)) {
cli_print(cli, "Directory %s doesn't exist", argv[0]);
return CLI_OK;
}
if (!boost::filesystem::is_directory(dir)) {
cli_print(cli, "Path %s isn't a directory", argv[0]);
return CLI_OK;
}
lmbctx->logpath = argv[0];
cli_print(cli, "LogFileDir set to %s", argv[0]);
return CLI_OK;
}
int cmd_set_monitorpath(struct cli_def *cli, UNUSED(const char *command), char *argv[],
int argc)
{
if (argc < 1) {
cli_print(cli, "usage: set monitorpath <dir>");
return CLI_OK;
}
struct LMBCTX *lmbctx = (struct LMBCTX *)cli_get_context(cli);
boost::unique_lock<boost::mutex> scoped_lock(lmbctx->io_mutex);
boost::filesystem::path dir(argv[0]);
if (!boost::filesystem::exists(dir)) {
cli_print(cli, "Directory %s doesn't exist", argv[0]);
return CLI_OK;
}
if (!boost::filesystem::is_directory(dir)) {
cli_print(cli, "Path %s isn't a directory", argv[0]);
return CLI_OK;
}
lmbctx->monitorpath = argv[0];
cli_print(cli, "monitorpath set to %s", argv[0]);
return CLI_OK;
}
int cmd_message(struct cli_def *cli, UNUSED(const char *command), UNUSED(char *argv[]), UNUSED(int argc)) {
@ -275,6 +347,8 @@ int Startcliloop(LMBCTX *lmbctx, int sockfd) {
cli_register_command(cli, c, "port", cmd_set_port, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Set Serial Port");
cli_register_command(cli, c, "startupmsg", cmd_set_startupmsg, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Set Serial Port");
cli_register_command(cli, c, "logfilepath", cmd_set_logfiledir, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Set Log File Directory");
cli_register_command(cli, c, "monitorpath", cmd_set_monitorpath, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Set Monitor File Directory");
cli_register_command(cli, NULL, "save", cmd_save, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Save Config");
@ -284,6 +358,10 @@ int Startcliloop(LMBCTX *lmbctx, int sockfd) {
cli_register_command(cli, c, "port", cmd_show_port, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show Configured Serial Port");
cli_register_command(cli, c, "messages", cmd_show_messages, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show Current Messages");
cli_register_command(cli, c, "startupmsg", cmd_show_startupmsgs, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show Current Messages");
cli_register_command(cli, c, "logfiledir", cmd_show_logfiledir, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show LogFile Directory");
cli_register_command(cli, c, "monitorpath", cmd_show_monitorpath, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show Monitor file Directory");
cli_register_command(cli, NULL, "message", cmd_message, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Set a Message to be displayed");
cli_register_command(cli, NULL, "clear", cmd_clear, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Clear a Message");

View file

@ -43,6 +43,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <boost/program_options.hpp>
#include "libcli/libcli.h"
#include "serial/serial.h"
#include "lmbd.hpp"
@ -50,17 +51,25 @@
#include "FileMonitor.hpp"
#define CLITEST_PORT 8000
LMB::Log::Logger *logger = NULL;
int main()
int main (int ac, char **av)
{
int s, x;
bool fork = true;
struct sockaddr_in addr;
int on = 1;
boost::program_options::options_description desc("Allowed Options");
desc.add_options()
("help", "Command Line Options")
("config", boost::program_options::value<std::string>(), "config file")
("debug", boost::program_options::value<int>(), "Debug Level")
;
#ifndef WIN32
signal(SIGCHLD, SIG_IGN);
@ -72,12 +81,35 @@ int main()
}
#endif
LMB::Log::Manager::setDefaultLevel(LMB::Log::Log::eInfo);
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(ac, av, desc), vm);
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
}
boost::filesystem::path cfgpath;
if (vm.count("config")) {
cfgpath = vm["config"].as<std::string>();
} else {
cfgpath = "/etc/LMBd.conf";
}
if (!boost::filesystem::exists(cfgpath)) {
std::cerr << "Can't find Config File at path " << cfgpath << std::endl;
return -1;
}
if (vm.count("debug")) {
fork = false;
LMB::Log::Manager::setDefaultLevel(LMB::Log::Log::eDebug);
} else
LMB::Log::Manager::setDefaultLevel(LMB::Log::Log::eInfo);
logger = new LMB::Log::Logger("LMBd");
struct LMBCTX *lmbctx = new LMBCTX;
lmbctx->driver = new Driver_DX();
@ -88,13 +120,15 @@ int main()
lmbctx->password = "password";
lmbctx->enablepass = "enable";
lmbctx->max_cli = 5;
lmbctx->monitorpath = "/tmp/test/";
lmbctx->monitorpath = "/var/spool/LMBd/";
lmbctx->messages = 6;
lmbctx->msgdisplay.resize(6);
lmbctx->logpath = "/var/log/LMBd";
lmbctx->maxlogfilesize = 1024*1024;
std::vector<std::string> displayedmsgs;
try {
lmbctx->load("/etc/LMBd.conf");
lmbctx->load(cfgpath.native());
} catch (std::exception& e) {
std::cerr << "Could Not Load Config File " << e.what() << std::endl;
exit(-1);

View file

@ -35,6 +35,7 @@
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/dynamic_bitset.hpp>
#include <boost/filesystem.hpp>
#include "serial/serial.h"
#include "libcli/libcli.h"
#include "LoggerCpp/LoggerCpp.h"
@ -42,6 +43,16 @@
class iDriver;
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
#define LMB_LOG_DEBUG() logger->debug()
@ -72,6 +83,8 @@ struct LMBCTX {
std::vector<boost::shared_ptr<boost::thread> > Clients;
unsigned int max_cli;
bool consolelog;
std::string logpath;
size_t maxlogfilesize;
void load(const std::string &filename)
{
// Create empty property tree object
@ -82,24 +95,50 @@ struct LMBCTX {
// Use the throwing version of get to find the debug filename.
// If the path cannot be resolved, an exception is thrown.
port= tree.get<std::string>("serial.port");
port= tree.get<std::string>("serial.port", "/dev/ttyUSB0");
// Use the default-value version of get to find the debug level.
// Note that the default value is used to deduce the target type.
username = tree.get<std::string>("username");
password = tree.get<std::string>("password");
enablepass = tree.get<std::string>("enablepass");
monitorpath = tree.get<std::string>("monitorpath");
if (tree.get<bool>("ConsoleLogging") == true) {
username = tree.get<std::string>("username", "admin");
password = tree.get<std::string>("password", "password");
enablepass = tree.get<std::string>("enablepass", "password");
boost::filesystem::path monpath(tree.get<std::string>("monitorpath", "/var/spool/LMBd"));
if (boost::filesystem::exists(monpath) && boost::filesystem::is_directory(monpath)) {
monitorpath = tree.get<std::string>("monitorpath", "/var/spool/LMBd");
} else {
throw std::runtime_error("monitorpath does not exist, or isn't a directory");
}
if (tree.get<bool>("ConsoleLogging", false) == true) {
LMB::Log::Config::addOutput(configList, "OutputConsole");
consolelog = true;
}
logger->setLevel(LMB::Log::Log::toLevel(tree.get<std::string>("ConsoleLogLevel").c_str()));
if (tree.get<std::string>("LogPath", "/var/log/LMBd/").length() > 0) {
boost::filesystem::path dir(tree.get<std::string>("LogPath", "/var/log/LMBd/"));
if (boost::filesystem::exists(dir) && boost::filesystem::is_directory(dir)) {
logpath = tree.get<std::string>("LogPath", "/var/log/LMBd/");
logpath += "/LMBd.Log";
} else {
throw std::runtime_error("LogPath does not exist, or isn't a directory");
}
}
LMB::Log::Config::addOutput(configList, "OutputFile");
LMB::Log::Config::setOption(configList, "filename", logpath.c_str());
std::string oldlogpath(logpath);
oldlogpath += ".old";
LMB::Log::Config::setOption(configList, "filename_old", oldlogpath.c_str());
LMB::Log::Config::setOption(configList, "max_startup_size", "0");
maxlogfilesize = tree.get<size_t>("MaxLogFileSize", 1024*1024);
LMB::Log::Config::setOption(configList, "max_size", patch::to_string(maxlogfilesize).c_str());
logger->setLevel(LMB::Log::Log::toLevel(tree.get<std::string>("ConsoleLogLevel", "Warning").c_str()));
for (unsigned int i = 1; i <= this->messages; i++) {
std::stringstream ss;
ss << "startupmessage." << std::dec << i;
this->startupmsg[i] = tree.get<std::string>(ss.str());
this->startupmsg[i] = tree.get<std::string>(ss.str(), "");
}
@ -120,6 +159,8 @@ struct LMBCTX {
tree.put("monitorpath", monitorpath);
tree.put("ConsoleLogging", consolelog);
tree.put("ConsoleLogLevel", LMB::Log::Log::toString(logger->getLevel()));
tree.put("LogPath", logpath);
tree.put("MaxLogFileSize", maxlogfilesize);
for (unsigned int i = 1; i <= this->messages; i++) {
std::stringstream ss;
ss << "startupmessage." << std::dec << i;