pouriyajamshidi / tcping

Ping TCP ports using tcping. Inspired by Linux's ping utility. Written in Go
MIT License
529 stars 57 forks source link

SQLite Output Fails with hyphens in hostname #239

Open andywhitaker opened 2 days ago

andywhitaker commented 2 days ago

It appears I get a failure when outputting to db if the server hostname includes a hyphen. I encountered while testing a site but was able to reproduce with a minimal example by creating two hostfile entries to localhost and running a lightweight server locally:

Hostnames:

Working example pinging "testserver" on port 8000:

tcping testserver 8000 --db ./testserver.db
TCPinging testserver on port 8000
^C
Statistics for "testserver" have been saved to "./testserver.db" in the table "testserver_8000_10_53_11_10_05_2024"

Failing example pinging "test-server" on port 8000:

tcping test-server 8000 --db ./testserver.db

Error writing to the database "./testserver.db"
err: sqlite: prepare "\n-- Organized row names together for better readability\nCREATE TABLE test-server_8000_10_49_06_10_05_2024 (\n    id INTEGER PRIMARY KEY,\n    event_type TEXT NOT NULL, -- for the data type eg. statistics, hostname change\n    timestamp DATETIME,\n    addr TEXT,\n    hostname TEXT,\n    port INTEGER,\n    hostname_resolve_retries INTEGER,\n\n    hostname_changed_to TEXT,\n    hostname_change_time DATETIME,\n\n    latency_min REAL,\n    latency_avg REAL,\n    latency_max REAL,\n\n\ttotal_duration TEXT,\n    start_time DATETIME,\n    end_time DATETIME,\n\n\tnever_succeed_probe INTEGER, -- value will be 1 if a probe never succeeded\n\tnever_failed_probe INTEGER, -- value will be 1 if a probe never failed\n    last_successful_probe DATETIME,\n    last_unsuccessful_probe DATETIME,\n\n    longest_uptime TEXT,\n    longest_uptime_start DATETIME,\n    longest_uptime_end DATETIME,\n\n    longest_downtime TEXT,\n    longest_downtime_start DATETIME,\n    longest_downtime_end DATETIME,\n\n    total_packets INTEGER,\n    total_packet_loss REAL,\n    total_successful_probes INTEGER,\n    total_unsuccessful_probes INTEGER,\n\n    total_uptime TEXT,\n    total_downtime TEXT\n);": 3:18: SQL logic error: near "-": syntax error

Thanks!

pouriyajamshidi commented 1 day ago

Hi @andywhitaker

Thanks for reporting this. We will get it fixed.