Skip to content

Commit 5084930

Browse files
committed
Add Rust-based monitoring tools with Python fallback
Introduce Rust implementations of sems-list-calls, sems-list-active-calls, sems-list-finished-calls, and sems-get-callproperties alongside the existing Python scripts. When cargo/rustc >= 1.38 is available, native binaries are built and installed. Otherwise, shell wrapper scripts delegate to the Python versions, keeping backwards compatibility fully intact. All tools accept --url to override the default XMLRPC endpoint.
1 parent 972edc4 commit 5084930

File tree

21 files changed

+881
-3
lines changed

21 files changed

+881
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ sems
3535
sems_tests
3636
sems-logfile-callextract
3737
sems-stats
38+
apps/monitoring/tools/target/
39+
apps/monitoring/tools/vendor/
40+
apps/monitoring/tools/.cargo/
41+
apps/monitoring/tools/Cargo.lock

Dockerfile-debian11

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ RUN apt install -y \
66
libspeex-dev libgsm1-dev libopus-dev libssl-dev python3-dev \
77
python3.9-dev libev-dev \
88
python3-sip-dev openssl libev-dev libmysqlcppconn-dev libevent-dev \
9-
libxml2-dev libcurl4-openssl-dev libhiredis-dev
9+
libxml2-dev libcurl4-openssl-dev libhiredis-dev \
10+
cargo rustc
1011

1112
RUN apt install -y \
1213
devscripts libbcg729-dev \

Dockerfile-debian12

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ RUN apt install -y \
88
python3-sip-dev openssl libev-dev libmysqlcppconn-dev libevent-dev \
99
libxml2-dev libcurl4-openssl-dev libhiredis-dev \
1010
libsamplerate-dev libmp3lame-dev libcodec2-dev \
11-
cmake dh-cmake dh-cmake-compat dh-sequence-cmake
11+
cmake dh-cmake dh-cmake-compat dh-sequence-cmake \
12+
cargo rustc
1213

1314

1415
RUN apt install -y \

Dockerfile-debian13

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ RUN apt install -y \
1111
libxml2-dev libcurl4-openssl-dev libhiredis-dev
1212

1313
RUN apt install -y devscripts libbcg729-dev \
14-
libsamplerate-dev libmp3lame-dev libcodec2-dev
14+
libsamplerate-dev libmp3lame-dev libcodec2-dev \
15+
cargo rustc
1516
RUN pip install sip --break-system-packages
1617
COPY . /sems
1718
WORKDIR /sems

Dockerfile-rhel10

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ RUN dnf install -y epel-release \
3030
rpm-build \
3131
mysql-connector-c++ \
3232
which \
33+
cargo rust \
3334
python3-mysqlclient --nogpgcheck
3435

3536
WORKDIR /

Dockerfile-rhel8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ RUN yum install -y \
2626
bcg729-devel codec2-devel flite-devel \
2727
lame-devel libmpg123-devel libsamplerate-devel \
2828
mysql-connector-c++-devel which man \
29+
cargo rust \
2930
python3-mysqlclient --nogpgcheck
3031

3132
RUN ln -s /usr/lib64/libpython3.6m.so /usr/lib64/libpython3.6.so

Dockerfile-rhel9

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ RUN yum install -y epel-release \
3131
rpm-build \
3232
mysql-connector-c++ \
3333
which \
34+
cargo rust \
3435
python3-mysqlclient --nogpgcheck
3536

3637
WORKDIR /

apps/monitoring/CMakeLists.txt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,72 @@ install(
55
tools/sems_list_calls.py tools/sems_list_finished_calls.py
66
DESTINATION ${SEMS_EXEC_PREFIX}/sbin)
77

8+
# Rust-based monitoring tools (require rustc >= 1.38 for edition 2018)
9+
find_program(CARGO cargo)
10+
set(SEMS_RUST_OK FALSE)
11+
if(CARGO)
12+
execute_process(
13+
COMMAND rustc --version
14+
OUTPUT_VARIABLE RUSTC_VERSION_OUTPUT
15+
OUTPUT_STRIP_TRAILING_WHITESPACE
16+
RESULT_VARIABLE RUSTC_RESULT)
17+
if(RUSTC_RESULT EQUAL 0)
18+
string(REGEX MATCH "[0-9]+\\.[0-9]+" RUSTC_VERSION "${RUSTC_VERSION_OUTPUT}")
19+
if(RUSTC_VERSION VERSION_GREATER_EQUAL "1.38")
20+
set(SEMS_RUST_OK TRUE)
21+
message(STATUS "Found cargo: ${CARGO}, rustc ${RUSTC_VERSION}")
22+
else()
23+
message(WARNING "rustc ${RUSTC_VERSION} found but >= 1.38 required; skipping Rust monitoring tools")
24+
endif()
25+
endif()
26+
endif()
27+
28+
if(SEMS_RUST_OK)
29+
set(SEMS_MONITORING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools)
30+
31+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
32+
set(CARGO_PROFILE "debug")
33+
set(CARGO_RELEASE_FLAG "")
34+
else()
35+
set(CARGO_PROFILE "release")
36+
set(CARGO_RELEASE_FLAG "--release")
37+
endif()
38+
39+
set(SEMS_MONITORING_BINARIES
40+
sems-list-calls
41+
sems-list-active-calls
42+
sems-list-finished-calls
43+
sems-get-callproperties)
44+
45+
add_custom_target(sems-monitoring-tools ALL
46+
COMMAND ${CARGO} build ${CARGO_RELEASE_FLAG}
47+
--manifest-path ${SEMS_MONITORING_DIR}/Cargo.toml
48+
COMMENT "Building sems monitoring tools (Rust)")
49+
50+
foreach(bin ${SEMS_MONITORING_BINARIES})
51+
install(PROGRAMS ${SEMS_MONITORING_DIR}/target/${CARGO_PROFILE}/${bin}
52+
DESTINATION ${SEMS_EXEC_PREFIX}/sbin)
53+
endforeach()
54+
else()
55+
message(WARNING "cargo/rustc not found or too old; installing Python wrapper scripts for monitoring tools")
56+
57+
set(MONITORING_FALLBACKS
58+
"sems-list-calls:sems_list_calls.py"
59+
"sems-list-active-calls:sems_list_active_calls.py"
60+
"sems-list-finished-calls:sems_list_finished_calls.py"
61+
"sems-get-callproperties:sems_get_callproperties.py")
62+
63+
foreach(entry ${MONITORING_FALLBACKS})
64+
string(REPLACE ":" ";" parts ${entry})
65+
list(GET parts 0 bin_name)
66+
list(GET parts 1 py_name)
67+
set(wrapper_path "${CMAKE_CURRENT_BINARY_DIR}/${bin_name}")
68+
file(WRITE ${wrapper_path}
69+
"#!/bin/sh\nexec \"$(dirname \"$0\")/${py_name}\" \"$@\"\n")
70+
install(PROGRAMS ${wrapper_path}
71+
DESTINATION ${SEMS_EXEC_PREFIX}/sbin)
72+
endforeach()
73+
endif()
74+
875
set(sems_module_name monitoring)
976
include(${CMAKE_SOURCE_DIR}/cmake/module.rules.txt)

apps/monitoring/tools/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[workspace]
2+
members = [
3+
"sems-monitoring-lib",
4+
"sems-list-calls",
5+
"sems-list-active-calls",
6+
"sems-list-finished-calls",
7+
"sems-get-callproperties",
8+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "sems-get-callproperties"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
sems-monitoring-lib = { path = "../sems-monitoring-lib" }

0 commit comments

Comments
 (0)