syslog - a simple syslog client

pull/73/head
susisstrolch 9 years ago
parent 0cb217046d
commit 9ec3a30c87
  1. 10
      Makefile
  2. 40
      esp-link/config.c
  3. 6
      esp-link/config.h
  4. 64
      esp-link/main.c
  5. 16
      html/home.html
  6. 6
      include/espmissingincludes.h
  7. 4
      serial/serbridge.c

@ -13,7 +13,7 @@
# Makefile heavily adapted to esp-link and wireless flashing by Thorsten von Eicken
# Lots of work, in particular to support windows, by brunnels
# Original from esphttpd and others...
#VERBOSE=1
# VERBOSE=1
# --------------- toolchain configuration ---------------
@ -23,7 +23,7 @@ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Base directory of the ESP8266 SDK package, absolute
# Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.4.0)
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.4.1_pre7)
# Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool
@ -83,7 +83,7 @@ LED_SERIAL_PIN ?= 14
CHANGE_TO_STA ?= yes
# Optional Modules
MODULES ?= mqtt rest
MODULES ?= mqtt rest syslog
# --------------- esphttpd config options ---------------
@ -198,6 +198,10 @@ ifneq (,$(findstring rest,$(MODULES)))
CFLAGS += -DREST
endif
ifneq (,$(findstring syslog,$(MODULES)))
CFLAGS += -DSYSLOG
endif
# which modules (subdirectories) of the project to include in compiling
LIBRARIES_DIR = libraries
MODULES += espfs httpd user serial cmd esp-link

@ -9,21 +9,31 @@
FlashConfig flashConfig;
FlashConfig flashDefault = {
33, 0, 0,
MCU_RESET_PIN, MCU_ISP_PIN, LED_CONN_PIN, LED_SERIAL_PIN,
115200,
"esp-link\0", // hostname
0, 0x00ffffff, 0, // static ip, netmask, gateway
0, // log mode
0, // swap uart (don't by default)
1, 0, // tcp_enable, rssi_enable
"\0", // api_key
0, 0, 0, // slip_enable, mqtt_enable, mqtt_status_enable
2, 1, // mqtt_timeout, mqtt_clean_session
1883, 60, // mqtt port, mqtt_keepalive
"\0", "\0", "\0", "\0", "\0", // mqtt host, client_id, user, password, status-topic
"\0", // system description
1, // rx_pullup
.seq=33, .magic=0, .crc=0,
.reset_pin = MCU_RESET_PIN, .isp_pin = MCU_ISP_PIN,
.conn_led_pin = LED_CONN_PIN, .ser_led_pin = LED_SERIAL_PIN,
.baud_rate = 115200,
.hostname = "ems-link02\0",
.staticip = 0,
.netmask = 0x00ffffff,
.gateway = 0,
.log_mode = 0,
.swap_uart = 0,
.tcp_enable = 1, .rssi_enable = 0,
.api_key = "\0",
.slip_enable = 0, .mqtt_enable = 0, .mqtt_status_enable = 0,
.mqtt_timeout = 2, .mqtt_clean_session = 1,
.mqtt_port = 1883, .mqtt_keepalive = 60,
.mqtt_host = "\0", .mqtt_clientid = "\0",
.mqtt_username= "\0", .mqtt_password = "\0", .mqtt_status_topic = "\0",
.sys_descr = "\0",
.rx_pullup = 1,
.sntp_server = "diskstation\0",
.syslog_host = "diskstation\0",
.syslog_minheap= 8192,
.syslog_filter = 7,
.syslog_showtick= 1,
.syslog_showdate= 0,
};
typedef union {

@ -25,6 +25,12 @@ typedef struct {
char mqtt_status_topic[32];
char sys_descr[129]; // system description
int8_t rx_pullup; // internal pull-up on RX pin
char sntp_server[32];
char syslog_host[32];
uint16_t syslog_minheap; // min. heap to allow queuing
uint8_t syslog_filter; // min. severity
uint8_t syslog_showtick; // show system tick (µs)
uint8_t syslog_showdate; // populate SYSLOG date field
} FlashConfig;
extern FlashConfig flashConfig;

@ -30,10 +30,18 @@
#include "config.h"
#include "log.h"
#include <gpio.h>
#include "syslog.h"
#include "sntp.h"
static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData);
static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData);
#define NOTICE(format, ...) do { \
LOG_NOTICE(format, ## __VA_ARGS__ ); \
os_printf(format "\n", ## __VA_ARGS__); \
} while ( 0 )
/*
This is the main url->function dispatching data struct.
In short, it's a struct with various URLs plus their handlers. The handlers can
@ -102,6 +110,17 @@ static char *flash_maps[] = {
"2MB:1024/1024", "4MB:1024/1024"
};
// enable SNTP client...
static void ICACHE_FLASH_ATTR enableSNTP() {
if (flashConfig.sntp_server[0]) {
NOTICE("SNTP timesource set to %s", flashConfig.sntp_server);
sntp_stop();
sntp_setservername(0, flashConfig.sntp_server);
// sntp_set_timezone(flashConfig.timezone); /* stay with GMT... */
sntp_init();
}
}
// Cgi to return various System information
static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
char buff[1024];
@ -115,13 +134,18 @@ static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
os_sprintf(buff, "{\"name\": \"%s\", \"reset cause\": \"%d=%s\", "
"\"size\": \"%s\"," "\"id\": \"0x%02lX 0x%04lX\"," "\"partition\": \"%s\","
"\"slip\": \"%s\"," "\"mqtt\": \"%s/%s\"," "\"baud\": \"%ld\","
"\"description\": \"%s\"" "}",
"\"description\": \"%s\","
"\"syslog\": \"%s\","
"\"sntp\": \"%s\" "
"}",
flashConfig.hostname, rst_info->reason, rst_codes[rst_info->reason],
flash_maps[system_get_flash_size_map()], fid & 0xff, (fid&0xff00)|((fid>>16)&0xff),
part_id ? "user2.bin" : "user1.bin",
flashConfig.slip_enable ? "enabled" : "disabled",
flashConfig.mqtt_enable ? "enabled" : "disabled",
mqttState(), flashConfig.baud_rate, flashConfig.sys_descr
mqttState(), flashConfig.baud_rate, flashConfig.sys_descr,
flashConfig.syslog_host,
flashConfig.sntp_server
);
jsonHeader(connData, 200);
@ -137,7 +161,27 @@ static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) {
int8_t n = getStringArg(connData, "name", flashConfig.hostname, sizeof(flashConfig.hostname));
int8_t d = getStringArg(connData, "description", flashConfig.sys_descr, sizeof(flashConfig.sys_descr));
if (n < 0 || d < 0) return HTTPD_CGI_DONE; // getStringArg has produced an error response
int8_t t = getStringArg(connData, "sntp", flashConfig.sntp_server, sizeof(flashConfig.sntp_server));
int8_t l = getStringArg(connData, "syslog", flashConfig.syslog_host, sizeof(flashConfig.syslog_host));
if (n < 0 || d < 0 || t < 0 || l < 0) return HTTPD_CGI_DONE; // getStringArg has produced an error response
// set defaults for syslog server
// we also should add a config or services web page...
if (l > 0) {
// set defaults for syslog server
syslog_init(flashConfig.syslog_host);
flashConfig.syslog_minheap= 8192;
flashConfig.syslog_filter = SYSLOG_PRIO_DEBUG;
flashConfig.syslog_showtick= 1; // show ESP µs Ticker in log message
flashConfig.syslog_showdate= 0; // Synology does a log rotate if timestamp is in the past, so we simply don't send it
os_printf("flashConfig: syslog: %s, minheap: %d, filter: %d, showtick: %d, showdate: %d\n",
flashConfig.syslog_host, flashConfig.syslog_minheap, flashConfig.syslog_filter, flashConfig.syslog_showtick, flashConfig.syslog_showdate);
}
// (re)start SNTP client if server setting is changed
if (t > 0) {
enableSNTP();
}
if (n > 0) {
// schedule hostname change-over
@ -225,18 +269,24 @@ void user_init(void) {
#endif
struct rst_info *rst_info = system_get_rst_info();
os_printf("Reset cause: %d=%s\n", rst_info->reason, rst_codes[rst_info->reason]);
os_printf("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x\n",
NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]);
NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x",
rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
rst_info->excvaddr, rst_info->depc);
uint32_t fid = spi_flash_get_id();
os_printf("Flash map %s, manuf 0x%02lX chip 0x%04lX\n", flash_maps[system_get_flash_size_map()],
NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()],
fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
NOTICE("** esp-link ready");
enableSNTP();
os_printf("** esp-link ready\n");
#ifdef MQTT
NOTICE("initializing MQTT");
mqtt_client_init();
#endif
NOTICE("initializing user application");
app_init();
NOTICE("waiting for work to do...");
}

@ -27,6 +27,20 @@
<tr><td>SLIP status</td><td class="system-slip"></td></tr>
<tr><td>MQTT status</td><td class="system-mqtt"></td></tr>
<tr><td>Serial baud</td><td class="system-baud"></td></tr>
<tr><td class="popup-target">Syslog Server</td><td>
<div class="click-to-edit system-syslog">
<span class="edit-off"></span>
<input class="edit-on" maxlength=31 hidden></input>
<div class="popup">Click to edit!<br>Use server [hostname:port] as UDP Syslog server</div>
</div>
</td></tr>
<tr><td class="popup-target">SNTP Server</td><td>
<div class="click-to-edit system-sntp">
<span class="edit-off"></span>
<input class="edit-on" maxlength=31 hidden></input>
<div class="popup">Click to edit!<br>Use server (f.e. 0.europe.pool.ntp.org) as NTP timesource</div>
</div>
</td></tr>
</tbody></table>
</div>
<div class="card">
@ -145,6 +159,8 @@
onLoad(function() {
makeAjaxInput("system", "description");
makeAjaxInput("system", "name");
makeAjaxInput("system", "sntp");
makeAjaxInput("system", "syslog");
fetchPins();
getWifiInfo();
getSystemInfo();

@ -3,6 +3,10 @@
#include <user_interface.h>
#include <eagle_soc.h>
#include <stdint.h>
#include <c_types.h>
#include <ets_sys.h>
#include <stdarg.h>
//Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere.
//MOST OF THESE ARE GUESSED! but they seem to work and shut up the compiler.
@ -43,6 +47,8 @@ void ets_update_cpu_frequency(int freqmhz);
#define DEBUG_SDK false
#endif
int ets_vsprintf(char *str, const char *format, va_list argptr);
int ets_vsnprintf(char *buffer, size_t sizeOfBuffer, const char *format, va_list argptr);
int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__((format(printf, 3, 4)));
int os_printf_plus(const char *format, ...) __attribute__((format(printf, 1, 2)));

@ -10,6 +10,7 @@
#include "console.h"
#include "slip.h"
#include "cmd.h"
#include "syslog.h"
#define SKIP_AT_RESET
@ -404,11 +405,12 @@ serbridgeConnectCb(void *arg)
#ifdef SERBR_DBG
os_printf("Accept port %d, conn=%p, pool slot %d\n", conn->proto.tcp->local_port, conn, i);
#endif
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_NOTICE, "esp-link", "Accept port %d, conn=%p, pool slot %d\n", conn->proto.tcp->local_port, conn, i);
if (i==MAX_CONN) {
#ifdef SERBR_DBG
os_printf("Aiee, conn pool overflow!\n");
#endif
syslog(SYSLOG_FAC_USER, SYSLOG_PRIO_WARNING, "esp-link", "Aiee, conn pool overflow!\n");
espconn_disconnect(conn);
return;
}

Loading…
Cancel
Save