added test server command

This commit is contained in:
Scott E. Graves 2025-02-22 04:08:07 -06:00
parent 7041688a64
commit d3a3f304ee
8 changed files with 231 additions and 25 deletions

View File

@ -45,6 +45,8 @@ class data_db;
void remove_stalled(std::string_view download_id, std::string_view title, void remove_stalled(std::string_view download_id, std::string_view title,
std::uint64_t episode_id, std::uint64_t movie_id, std::uint64_t episode_id, std::uint64_t movie_id,
const server_cfg &server, data_db *state_db = nullptr); const server_cfg &server, data_db *state_db = nullptr);
[[nodiscard]] auto test_server(const server_cfg &server) -> int;
} // namespace monitarr } // namespace monitarr
#endif // LIBMONITARR_INCLUDE_ACTIONS_HPP_ #endif // LIBMONITARR_INCLUDE_ACTIONS_HPP_

View File

@ -171,6 +171,48 @@ auto load_config(std::string &cfg_file) -> app_config {
return cfg; return cfg;
} }
std::for_each(
cfg.server_list.begin(), cfg.server_list.end(), [&](server_cfg &srv) {
utils::string::trim(srv.api_key);
if (srv.api_key.empty()) {
throw utils::error::create_exception(
function_name, {
"server 'api_key' must not be empty",
});
}
utils::string::trim(srv.api_version);
if (srv.api_version.empty()) {
throw utils::error::create_exception(
function_name, {
"server 'api_version' must not be empty",
});
}
utils::string::trim(srv.id);
if (srv.id.empty()) {
throw utils::error::create_exception(
function_name, {
"server 'id' must not be empty",
});
}
if (srv.timeout.count() <= 0) {
throw utils::error::create_exception(
function_name, {
"server 'timeout' must be greater than 0",
});
}
utils::string::trim(srv.url);
if (srv.url.empty()) {
throw utils::error::create_exception(
function_name, {
"server 'url' must not be empty",
});
}
});
{ {
auto iter = std::ranges::adjacent_find( auto iter = std::ranges::adjacent_find(
cfg.server_list, cfg.server_list,
@ -202,30 +244,27 @@ auto load_config(std::string &cfg_file) -> app_config {
}); });
} }
// std::ranges::for_each(id_names, [&](std::string_view name) { std::ranges::for_each(cfg.server_list, [&](const auto &srv) {
// std::ranges::for_each(cfg.server_list, [&](auto &&srv) { std::size_t count{};
// auto count = std::ranges::count(srv.id, name); std::ranges::for_each(id_names, [&count, &srv](std::string_view name) {
// }); for (std::size_t pos = 0U;
// auto count = std::ranges::count( (pos = srv.id.find(name, pos)) != std::string::npos; ++pos) {
// std::accumulate(cfg.server_list.begin(), cfg.server_list.end(), ++count;
// std::vector<std::string_view>(), }
// [](auto &&list, auto &&srv) { });
// list.push_back(srv.id);
// return list; if (count == 1U) {
// }), return;
// name); }
// if (count <= 1U) {
// return; throw utils::error::create_exception(
// } function_name, {
// "server id",
// throw utils::error::create_exception( srv.id,
// function_name, { "must contain only one of the following values",
// "server id", fmt::format("{}", id_names),
// name, });
// "must contain only one of the following });
// values", fmt::format("{}", id_names),
// });
// });
} }
return cfg; return cfg;
@ -329,4 +368,27 @@ void remove_stalled(std::string_view download_id, std::string_view title,
server.id, server.url, title, server.id, server.url, title,
search_id, response->status)); search_id, response->status));
} }
auto test_server(const server_cfg &server) -> int {
MONITARR_USES_FUNCTION_NAME();
auto cli = create_client(server);
auto response = cli.Get("/api");
if (not response) {
utils::error::handle_error(
function_name, fmt::format("get api request failed|{}|{}|no response",
server.id, server.url));
return 3;
}
if (response->status != httplib::StatusCode::OK_200) {
utils::error::handle_error(
function_name, fmt::format("get api request failed|{}|{}|{}", server.id,
server.url, response->status));
return 3;
}
return 0;
}
} // namespace monitarr } // namespace monitarr

View File

@ -0,0 +1,33 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef LIBMONITARR_INCLUDE_TEST_CMD_HPP_
#define LIBMONITARR_INCLUDE_TEST_CMD_HPP_
#include "utils/config.hpp"
namespace monitarr {
struct app_config;
[[nodiscard]] auto test_cmd(const app_config &cfg) -> int;
} // namespace monitarr
#endif // LIBMONITARR_INCLUDE_TEST_CMD_HPP_

View File

@ -33,6 +33,7 @@
#include "run_cmd.hpp" #include "run_cmd.hpp"
#include "settings.hpp" #include "settings.hpp"
#include "show_cmd.hpp" #include "show_cmd.hpp"
#include "test_cmd.hpp"
#include "usage_cmd.hpp" #include "usage_cmd.hpp"
#include "utils/common.hpp" #include "utils/common.hpp"
#include "utils/file.hpp" #include "utils/file.hpp"
@ -101,6 +102,8 @@ auto main(int argc, char **argv) -> int {
ret = run_cmd(cfg, log_dir); ret = run_cmd(cfg, log_dir);
} else if (has_arg("-s", argc, argv)) { } else if (has_arg("-s", argc, argv)) {
ret = show_cmd(argc, argv, cfg); ret = show_cmd(argc, argv, cfg);
} else if (has_arg("-t", argc, argv)) {
ret = test_cmd(cfg);
} else { } else {
ret = usage_cmd(); ret = usage_cmd();
if (ret == 0) { if (ret == 0) {

View File

@ -1,3 +1,24 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <execution> #include <execution>
#include "run_cmd.hpp" #include "run_cmd.hpp"

View File

@ -1,3 +1,24 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "show_cmd.hpp" #include "show_cmd.hpp"
#include "actions.hpp" #include "actions.hpp"

View File

@ -0,0 +1,41 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "test_cmd.hpp"
#include "actions.hpp"
#include "settings.hpp"
namespace monitarr {
auto test_cmd(const app_config &cfg) -> int {
MONITARR_USES_FUNCTION_NAME();
auto ret{0};
for (const auto &srv : cfg.server_list) {
auto test_ret = test_server(srv);
if (ret == 0 && test_ret != 0) {
ret = test_ret;
}
}
return ret;
}
} // namespace monitarr

View File

@ -1,3 +1,24 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "usage_cmd.hpp" #include "usage_cmd.hpp"
#include "utils/error.hpp" #include "utils/error.hpp"
@ -18,7 +39,9 @@ auto usage_cmd() -> int {
" monitarr -r\n" " monitarr -r\n"
" run monitarr server\n" " run monitarr server\n"
" monitarr -s -i <index> -id <record id>\n" " monitarr -s -i <index> -id <record id>\n"
" show record id details at configuration index\n"); " show record id details at configuration index\n"
" monitarr -t\n"
" test all server connectivity\n");
return 0; return 0;
} }