Compare commits

..

130 Commits

Author SHA1 Message Date
L_DelOff 406f3ba6b3 Merge pull request 'fix' (#44) from feature/task-43 into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
Reviewed-on: #44
2024-11-24 18:12:26 +03:00
L_DelOff 0cd6dd0808 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master Build started... Details
2024-11-24 18:11:01 +03:00
L_DelOff 7bdcf10cd2 Merge pull request 'feature/task-38-roles' (#42) from feature/task-38-roles into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head Something is wrong with the build of this commit Details
Reviewed-on: #42
2024-11-24 17:59:47 +03:00
L_DelOff a648865083 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master Build queued... Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
2024-11-24 17:56:15 +03:00
L_DelOff 68d0fb2ced fix 2024-11-24 17:39:48 +03:00
L_DelOff d23910af9e убрал базу данных 2024-11-24 17:17:56 +03:00
L_DelOff 93e04a7e56 рефактор 2024-11-16 16:35:00 +03:00
L_DelOff 23b5f02438 Merge pull request 'feature/task-38-roles' (#39) from feature/task-38-roles into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
Reviewed-on: #39
2024-01-21 20:17:35 +03:00
L_DelOff a03a6abdfc Отображаются только доступные для роли команды
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
2024-01-21 20:16:27 +03:00
L_DelOff 0fe1d7e670 Паттерн цепочка с автоподтягиванием классов-команд
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
2024-01-21 18:46:56 +03:00
L_DelOff c3711bb571 Рефактор
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
2024-01-21 15:38:00 +03:00
L_DelOff 39c2d6e6fc Статус теперь пытается реконнект сделать
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
2023-12-17 17:20:12 +03:00
L_DelOff 21f4a71c63 Уведомление о перезапуске
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
2023-12-17 16:41:24 +03:00
L_DelOff 25b73feb48 Таймауты на соединение 2023-12-17 15:11:13 +03:00
L_DelOff 3a967e399b Авторестарт контейнеров при падении 2023-12-17 14:57:12 +03:00
L_DelOff bebf1b2916 Merge pull request 'fix' (#37) from feature/task-11-mdadm_status into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
Reviewed-on: #37
2023-11-22 20:49:51 +03:00
L_DelOff 62a473000a fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master Build queued... Details
2023-11-22 20:48:51 +03:00
L_DelOff b842114bb3 Merge pull request 'fix' (#36) from feature/task-11-mdadm_status into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
Reviewed-on: #36
2023-11-22 20:43:28 +03:00
L_DelOff 187e20ad9d fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master Build queued... Details
2023-11-22 20:42:47 +03:00
L_DelOff 6545e01f9b Merge pull request 'feature/task-11-mdadm_status' (#35) from feature/task-11-mdadm_status into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
Reviewed-on: #35
2023-11-22 20:10:07 +03:00
L_DelOff f2a74b9f84 добавил mdadm
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
2023-11-22 20:08:23 +03:00
L_DelOff 15d6894013 уточнил пример ямлика 2023-11-22 19:11:03 +03:00
L_DelOff 5bd78701e9 hotfix
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-22 18:58:53 +03:00
L_DelOff 74e5e2b017 hotfix
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-22 18:55:42 +03:00
L_DelOff 30772ec123 Merge pull request 'fix' (#33) from feature/task-30-docker into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
Reviewed-on: #33
2023-11-22 18:51:11 +03:00
L_DelOff c5d7689b97 Удаление старых образов перед деплоем
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master Build queued... Details
2023-11-22 18:50:36 +03:00
L_DelOff 5b0decff19 Merge pull request 'Удаление старых образов перед деплоем' (#32) from feature/task-30-docker into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Reviewed-on: #32
2023-11-22 18:48:16 +03:00
L_DelOff 2bca814b3f Удаление старых образов перед деплоем
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
2023-11-22 18:45:22 +03:00
L_DelOff 24839dc3fe Merge pull request 'feature/task-30-docker' (#31) from feature/task-30-docker into master
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
Reviewed-on: #31
2023-11-22 11:36:39 +03:00
L_DelOff 2b8a5f326c убрал лишние шаги
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/pr-master This commit looks good Details
2023-11-22 11:32:44 +03:00
L_DelOff 180e1e6be4 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 23:21:59 +03:00
L_DelOff 1a1fca9325 fix 2023-11-21 23:21:34 +03:00
L_DelOff e416a84bf7 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 23:13:21 +03:00
L_DelOff dcd357c6e0 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 23:07:59 +03:00
L_DelOff 43958b0d7c fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 23:06:14 +03:00
L_DelOff c8ff9725e5 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 23:02:25 +03:00
L_DelOff bac9f84092 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 23:01:20 +03:00
L_DelOff 38a989e223 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 22:59:24 +03:00
L_DelOff 2b782867c9 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 22:57:56 +03:00
L_DelOff 3a0866dfa4 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 22:54:57 +03:00
L_DelOff 386dceed36 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 22:52:56 +03:00
L_DelOff 5d4370d932 fix 2023-11-21 22:52:17 +03:00
L_DelOff 23effc5fe6 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 22:49:46 +03:00
L_DelOff e259bb0262 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 22:32:46 +03:00
L_DelOff 9849a46a40 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 22:22:40 +03:00
L_DelOff 757850aae6 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 22:16:55 +03:00
L_DelOff 431e777988 add application.yml
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 22:15:43 +03:00
L_DelOff 8b8833cd2b fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 17:53:32 +03:00
L_DelOff 754ae67714 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 14:05:11 +03:00
L_DelOff 7d929254dd fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 14:02:48 +03:00
L_DelOff d822059e4e fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 14:00:18 +03:00
L_DelOff 0fecaa501b fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 13:59:29 +03:00
L_DelOff 034387af16 fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 13:57:58 +03:00
L_DelOff 07b27cb6de очистка от неиспользуемых образов
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 13:53:25 +03:00
L_DelOff 28ec8dcd64 очистка от неиспользуемых образов
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 13:50:35 +03:00
L_DelOff de303fcd8e очистка от неиспользуемых образов
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 13:47:06 +03:00
L_DelOff 35a8d6a8c7 очистка от неиспользуемых образов
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-21 13:43:36 +03:00
L_DelOff bf070c29a1 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 13:33:21 +03:00
L_DelOff 395da1739b CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-21 13:28:03 +03:00
L_DelOff 34744f93ec CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 22:13:19 +03:00
L_DelOff a20b0c4963 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 22:07:30 +03:00
L_DelOff 94485ab9d2 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 22:02:23 +03:00
L_DelOff 204dbc5f73 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 21:50:45 +03:00
L_DelOff 98bc9633be CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 21:47:54 +03:00
L_DelOff 8bdc56bd8a CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 21:32:28 +03:00
L_DelOff 051e201525 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 21:30:28 +03:00
L_DelOff b68520ffa4 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 21:25:10 +03:00
L_DelOff 74078b120c CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 21:22:50 +03:00
L_DelOff 94285d88b7 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 21:20:56 +03:00
L_DelOff 008b173b70 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 21:19:20 +03:00
L_DelOff 0ba76e16b2 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 21:17:34 +03:00
L_DelOff bdb19c81ca CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 21:06:00 +03:00
L_DelOff d56b5a5617 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 20:59:34 +03:00
L_DelOff 182f850a3b CI/CD fix
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 20:58:23 +03:00
L_DelOff 11c0b4f369 CI/CD fix
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 20:55:01 +03:00
L_DelOff a6151fb01e CI/CD fix
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 20:53:40 +03:00
L_DelOff 3c53ea17a5 CI/CD
Hedgehog_server_CI/ServerMonitorBot/pipeline/head This commit looks good Details
Hedgehog_server_CD/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 20:49:56 +03:00
L_DelOff 3b505398e4 build docker stage
Hedgehog_server/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-20 20:08:55 +03:00
L_DelOff ead94bea2f build docker stage
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 20:06:34 +03:00
L_DelOff ecfd0a9ae5 build docker stage
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 19:59:20 +03:00
L_DelOff 7a0c2fde66 fix
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 19:54:58 +03:00
L_DelOff 56a74a8b49 Добавил стадию теста
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-20 19:52:32 +03:00
L_DelOff 0863650ddc log errors
Hedgehog_server/ServerMonitorBot/pipeline/head This commit looks good Details
2023-11-19 22:20:29 +03:00
L_DelOff 02a4b5081f log errors
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 22:16:52 +03:00
L_DelOff 9ef9ad18cf fix
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 22:15:16 +03:00
L_DelOff fd39b88296 fix
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 22:12:16 +03:00
L_DelOff 74f02e7827 Merge remote-tracking branch 'origin/devops' into feature/task-30-docker
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 22:10:39 +03:00
L_DelOff dc07591612 агент
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 22:03:19 +03:00
L_DelOff 0f9721f562 агент
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 22:02:30 +03:00
L_DelOff 742d246cdb агент
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 21:53:21 +03:00
L_DelOff 0ac12deed3 агент
ServerMonitorBot/test/ServerMonitorBot/pipeline/head There was a failure building this commit Details
Hedgehog_server/ServerMonitorBot/pipeline/head There was a failure building this commit Details
2023-11-19 20:45:21 +03:00
L_DelOff 9a4652b8f2 агент 2023-11-19 20:40:53 +03:00
L_DelOff edd29ea029 агент 2023-11-19 20:33:11 +03:00
L_DelOff 7838e60a82 агент 2023-11-19 20:31:37 +03:00
L_DelOff 02a56ee434 агент 2023-11-19 20:29:09 +03:00
l_deloff d60187cc07 test 2023-11-19 15:10:55 +00:00
L_DelOff 6359c59af9 агент 2023-11-19 18:07:57 +03:00
L_DelOff c84e935f05 агент 2023-11-19 17:54:15 +03:00
L_DelOff f9ad7fddbd агент 2023-11-19 17:38:39 +03:00
L_DelOff f011205a22 агент 2023-11-19 17:32:19 +03:00
l_deloff 5920067b02 тестю билд 2023-11-19 14:27:46 +00:00
l_deloff 9e6cba52f6 Коммит от ТУЗ 2023-11-19 14:20:11 +00:00
l_deloff 638dc42a46 KAKASIKI 2023-11-19 14:11:02 +00:00
l_deloff fd4248d722 KUKUSIKI 2023-11-19 14:07:01 +00:00
L_DelOff b71b4db66e Flyway 2023-11-17 09:29:19 +03:00
L_DelOff 9ee1a4de3c Merge pull request 'Добавил кнопку слежения за температурой CPU' (#29) from feature/task-8-CPUtemp into master
Reviewed-on: L_DelOff/ServerMonitorBot#29
2023-08-13 21:01:29 +03:00
L_DelOff c42781c5ee Добавил кнопку слежения за температурой CPU 2023-08-13 21:00:43 +03:00
L_DelOff daf9e9cb06 Merge pull request 'Добавил кнопку слежения за температурой дисков' (#28) from feature/task-10-hddtemp into master
Reviewed-on: L_DelOff/ServerMonitorBot#28
2023-08-13 20:06:53 +03:00
L_DelOff d0be1f0a62 Добавил кнопку слежения за температурой дисков 2023-08-13 19:36:12 +03:00
L_DelOff e75c496ea8 Merge pull request 'Применил паттерн Template' (#27) from feature/task-26-template into master
Reviewed-on: L_DelOff/ServerMonitorBot#27
2023-08-13 18:28:05 +03:00
L_DelOff 32147b0e52 Применил паттерн Template 2023-08-13 18:24:29 +03:00
L_DelOff 99d06bb3bc Merge pull request 'feature/task-6-security' (#24) from feature/task-6-security into master
Reviewed-on: L_DelOff/ServerMonitorBot#24
2023-08-12 19:45:20 +03:00
L_DelOff ad7ee9a96c Добавлена ролевая модель 2023-08-12 19:44:30 +03:00
L_DelOff e1ea86b36b Автозагрузка пользователей в БД 2023-08-12 19:43:49 +03:00
L_DelOff 148c511b9e Перестройка БД 2023-08-12 19:43:04 +03:00
L_DelOff f08d88355a Merge pull request 'feature/task-15-add_db' (#23) from feature/task-15-add_db into master
Reviewed-on: L_DelOff/ServerMonitorBot#23
2023-08-12 14:47:02 +03:00
L_DelOff 4974796f0a Добавил сущности role и user 2023-08-10 22:21:30 +03:00
L_DelOff 047502916a Добавил spring jpa и liquibase 2023-08-09 22:18:02 +03:00
L_DelOff c174f36848 Merge pull request 'Фикс багов' (#5) from bugfix/fix-issues into master
Reviewed-on: L_DelOff/ServerMonitorBot#5
2023-08-08 22:36:44 +03:00
L_DelOff 619996b913 Фикс багов 2023-08-08 22:36:06 +03:00
L_DelOff 0cfdd37702 Merge pull request 'feature/add-uname-command' (#4) from feature/add-uname-command into master
Reviewed-on: L_DelOff/ServerMonitorBot#4
2023-08-08 21:02:32 +03:00
L_DelOff e6fac12e15 Если сервер один, то не показываю кнопку "все сервера" 2023-08-08 21:01:10 +03:00
L_DelOff b6147e9e91 Реализована команда uname 2023-08-07 23:49:02 +03:00
L_DelOff fcd4929e0c Рефактор 2023-08-06 23:01:58 +03:00
L_DelOff 7b18162d30 Добавлена кнопка uname, пока не полный функционал 2023-08-06 00:55:44 +03:00
L_DelOff 26d9f83917 Merge pull request 'Добавлена кнопка статус соединения' (#3) from feature/add-status-button into master
Reviewed-on: L_DelOff/ServerMonitorBot#3
2023-08-05 23:01:51 +03:00
L_DelOff 6d56771999 Добавлена кнопка статус соединения 2023-08-05 22:58:19 +03:00
L_DelOff 91efa22e12 Merge pull request 'При запуске идёт подключение ко всем серверам' (#2) from feature/add_ssh_connect into master
Reviewed-on: L_DelOff/ServerMonitorBot#2
2023-08-05 19:35:01 +03:00
L_DelOff 61aaba99a6 При запуске идёт подключение ко всем серверам 2023-08-05 19:34:06 +03:00
L_DelOff 687c99b80d Merge pull request 'Настойка телеграм бота' (#1) from feature/TelegramBotExample into master
Reviewed-on: L_DelOff/ServerMonitorBot#1
2023-08-05 17:25:37 +03:00
44 changed files with 1465 additions and 54 deletions

11
Dockerfile Normal file
View File

@ -0,0 +1,11 @@
# Используем официальный образ OpenJDK 17 как базовый образ
FROM openjdk:17
# Установка рабочей директории внутри контейнера
WORKDIR /app
# Копируем JAR-файл приложения из локальной директории внутрь контейнера
COPY ServerMonitorBot-0.0.1-SNAPSHOT.jar app.jar
# Команда для запуска Spring Boot приложения при старте контейнера
CMD ["java", "-jar", "app.jar"]

71
Jenkinsfile_CD Normal file
View File

@ -0,0 +1,71 @@
pipeline {
agent {
docker {
image 'maven:3.9.5-eclipse-temurin-17'
args '-v /root/.m2:/root/.m2'
}
}
environment {
SSH_HOST = credentials('ROCK_PI_5_SSH_HOST')
SSH_PORT = credentials('ROCK_PI_5_SSH_PORT')
SSH_USER = credentials('ROCK_PI_5_SSH_USER')
SSH_PASS = credentials('ROCK_PI_5_SSH_PASS')
PATH_TO_DEV_FOLDER = credentials('SERVERMONITORBOT_PATH_TO_DEV_FOLDER')
IMAGE_NAME = 'servermonitorbot'
IMAGE_VERSION = 'latest'
}
stages {
stage('Init container') {
steps {
sh 'apt-get update && apt-get install -y sshpass openssh-client'
}
}
stage('Build') {
steps {
withCredentials([file(credentialsId: 'SERVERMONITORBOT_APPLICATION_YAML', variable: 'application_yaml')]) {
sh "cp -f \$application_yaml src/main/resources/application.yml"
}
sh 'mvn -B -DskipTests -X clean package spring-boot:repackage'
}
}
stage('Stop container') {
steps {
sh """
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'cd ${PATH_TO_DEV_FOLDER} && docker compose down'
"""
}
}
stage('Remove old image') {
steps {
sh """
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'docker image rm -f ${IMAGE_NAME}-app:${IMAGE_VERSION} || true'
"""
}
}
stage('Deploy') {
steps {
script {
sh """
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'mkdir -p ${PATH_TO_DEV_FOLDER}'
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'rm -f ${PATH_TO_DEV_FOLDER}/{*.*}'
sshpass -p ${SSH_PASS} scp -o StrictHostKeyChecking=no -P ${SSH_PORT} target/*.jar ${SSH_USER}@${SSH_HOST}:${PATH_TO_DEV_FOLDER}/
sshpass -p ${SSH_PASS} scp -o StrictHostKeyChecking=no -P ${SSH_PORT} Dockerfile ${SSH_USER}@${SSH_HOST}:${PATH_TO_DEV_FOLDER}/
sshpass -p ${SSH_PASS} scp -o StrictHostKeyChecking=no -P ${SSH_PORT} docker-compose.yml ${SSH_USER}@${SSH_HOST}:${PATH_TO_DEV_FOLDER}/
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'cd ${PATH_TO_DEV_FOLDER} && docker build --no-cache -t ${IMAGE_NAME}:${IMAGE_VERSION} .'
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'cd ${PATH_TO_DEV_FOLDER} && docker compose up -d'
"""
}
}
}
stage('Remove useless images') {
steps {
sh """
sshpass -p ${SSH_PASS} ssh -o StrictHostKeyChecking=no ${SSH_USER}@${SSH_HOST} -p ${SSH_PORT} 'docker image prune --all --force'
"""
}
}
}
}

15
Jenkinsfile_CI Normal file
View File

@ -0,0 +1,15 @@
pipeline {
agent {
docker {
image 'maven:3.9.5-eclipse-temurin-17'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests -X clean package spring-boot:repackage'
}
}
}
}

6
docker-compose.yml Normal file
View File

@ -0,0 +1,6 @@
version: '3'
services:
app:
build:
context: .
restart: always

20
pom.xml
View File

@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.2</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ru.ldeloff</groupId>
@ -15,13 +15,13 @@
<description>ServerMonitorBot</description>
<properties>
<java.version>17</java.version>
<start-class>ru.ldeloff.servermonitorbot.ServerMonitorBotApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -40,10 +40,13 @@
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>6.7.0</version>
<version>6.9.7.1</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
</dependencies>
<build>
@ -59,6 +62,13 @@
</exclude>
</excludes>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

View File

@ -2,8 +2,13 @@ package ru.ldeloff.servermonitorbot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;
import ru.ldeloff.servermonitorbot.model.server.SshServers;
@SpringBootApplication
@EnableScheduling
@EnableConfigurationProperties(SshServers.class)
public class ServerMonitorBotApplication {
public static void main(String[] args) {

View File

@ -0,0 +1,149 @@
package ru.ldeloff.servermonitorbot.commands;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import ru.ldeloff.servermonitorbot.model.user.Role;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.service.SshService;
import ru.ldeloff.servermonitorbot.view.ServerListButtons;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@Slf4j
@RequiredArgsConstructor
public abstract class CommandTemplate {
private final UpdateUtil updateUtil;
private final ServerListButtons serverListButtons;
public final SshService sshService;
private final MessagingService messagingService;
@Getter
@Setter
private List<Role> expectedRole = List.of(Role.ADMIN);
@Getter
@Setter
private String name;
public boolean execute(Update update) {
if (!isExecute(update)) {
return false;
}
User user = updateUtil.getUser(update);
String message = updateUtil.getMessage(update);
SendMessage answer = new SendMessage();
answer.setChatId(user.getTelegramId());
answer.setText(message);
if (!updateUtil.roleChecker(update, expectedRole)) {
logNotAuth(user, message);
messagingService.send(actionForNotAuth(user, answer));
return true;
}
String type = checkTypeCommand(update);
switch (type) {
case "aggregate":
logSuccess(user, message);
messagingService.send(executeAggregate(user, answer));
return true;
case "command":
logSuccess(user, message);
messagingService.send(executeCommand(user, answer));
return true;
default:
return false;
}
}
// Методы для проверки команды
private boolean isExecute(Update update) {
if (update.hasMessage()) {
if (update.getMessage().hasText()) {
String messageText = update.getMessage().getText();
if (Objects.equals(messageText, name)) {
log.debug("Команда {} будет выполнена", messageText);
return true;
}
}
} else if (update.hasCallbackQuery()) {
String [] tags = update.getCallbackQuery().getData().split(":");
if (tags.length > 1) {
if (Objects.equals(tags[0], name)) {
log.debug("Команда {} будет выполнена", tags[0]);
return true;
}
} else {
log.debug("Команда не будет выполнена");
return false;
}
}
log.debug("Команда не будет выполнена");
return false;
}
private String checkTypeCommand(Update update) {
if (update.hasMessage()) {
if (update.getMessage().hasText()) {
return "aggregate";
}
} else if (update.hasCallbackQuery()) {
String [] tags = update.getCallbackQuery().getData().split(":");
if (tags.length > 1) {
return "command";
} else {
return "error";
}
}
return "error";
}
// Методы при верных условиях
void logSuccess(User user, String message) {
log.info("Получена команда '{}' от {} ({}). OK", message, user.getLogin(), user.getTelegramId());
}
public SendMessage executeAggregate(User user, SendMessage message) {
return serverListButtons.uiForm(message);
}
SendMessage executeCommand(User user, SendMessage message) {
String [] tags = Arrays.stream(message.getText().split(":"))
.map(String::trim)
.toArray(String[]::new);
if (tags[1].equals("all")) {
message.setText(executeCommandAllHost());
} else {
message.setText(Objects.requireNonNull(executeCommandSpecificHost(tags[1])));
}
return message;
}
private String executeCommandAllHost() {
List<SshServer> servers = sshService.getHealthSshServers();
StringBuilder response = new StringBuilder();
servers.forEach(server -> response.append(executeCommandSpecificHost(server.getName())).append("\n"));
return response.toString();
}
public abstract String executeCommandSpecificHost(String serverName);
// Методы при неверных условиях
void logNotAuth(User user, String message) {
log.warn("Получена команда '" + message + "' от " + user.getLogin()
+ " (" + user.getTelegramId() + "). Нет прав");
}
private SendMessage actionForNotAuth(User user, SendMessage message) {
message.setText("У пользователя " + user.getLogin() + " (" + user.getTelegramId()
+ ") недостаточно прав для выполнения этой команды");
return message;
}
}

View File

@ -0,0 +1,49 @@
package ru.ldeloff.servermonitorbot.commands.cpu.temp.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.SshCommand;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
import ru.ldeloff.servermonitorbot.service.SshService;
import ru.ldeloff.servermonitorbot.view.ServerListButtons;
import java.util.Objects;
import java.util.Optional;
@Service
@Slf4j
public class CpuTemp extends CommandTemplate {
public CpuTemp(UpdateUtil updateUtil, ServerListButtons serverListButtons, SshService sshService, MessagingService messagingService) {
super(updateUtil, serverListButtons, sshService, messagingService);
setName("CPU.temp");
}
@Override
public String executeCommandSpecificHost(String serverName) {
try {
Optional<SshServer> server = sshService.getAllSshServers()
.stream()
.filter(x -> x.getName().equals(serverName))
.findFirst();
if (server.isPresent()) {
SshCommand result = sshService.execute(new SshCommand("cat /sys/class/thermal/thermal_zone0/temp", 100, server.get()));
return server.get().getName() + ": \n" +
(Objects.isNull(result.getResponse()) ? "ошибка при выполнении команды" :
String.format("%.1f",
Double.parseDouble(result.getResponse().replaceAll("\n", ""))/1000))
+ "°C";
} else {
log.error("Ошибка при выполнении команды 'CPUtemp'. Искомый сервер ({}) не найден", serverName);
return null;
}
} catch (NumberFormatException e) {
log.error("Ошибка при выполнении команды 'CPUtemp'" ,e.getMessage());
return "Сервер " + serverName + " не поддерживает команду 'CPUtemp'";
}
}
}

View File

@ -0,0 +1,87 @@
package ru.ldeloff.servermonitorbot.commands.hdd.mdadm.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.SshCommand;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
import ru.ldeloff.servermonitorbot.service.SshService;
import ru.ldeloff.servermonitorbot.view.ServerListButtons;
import java.util.*;
@Service
@Slf4j
public class MdadmStatus extends CommandTemplate {
public MdadmStatus(UpdateUtil updateUtil, ServerListButtons serverListButtons, SshService sshService, MessagingService messagingService) {
super(updateUtil, serverListButtons, sshService, messagingService);
setName("MDADM");
}
@Override
public String executeCommandSpecificHost(String serverName) {
Optional<SshServer> server = sshService.getAllSshServers()
.stream()
.filter(x -> x.getName().equals(serverName))
.findFirst();
if (server.isPresent()) {
// узнаю скок рейдов
SshCommand sshCommandRaid = sshService.execute(new SshCommand("mdadm --detail --scan", 500, server.get()));
List<String> raidNames = parseRaidNames(sshCommandRaid);
// Для каждого рейда надо выяснить статус
StringBuilder result = new StringBuilder();
raidNames.forEach(raid -> {
result.append(raid).append(":\n");
SshCommand sshCommandHdd = sshService.execute(new SshCommand("mdadm --detail " + raid, 500, server.get()));
List<String> hdds = parseHddState(sshCommandHdd);
hdds.forEach(hdd -> result.append(hdd).append("\n"));
});
return server.get().getName() + ": \n" + result;
} else {
log.error("Ошибка при выполнении команды 'mdadm'. Искомый сервер ({}) не найден", serverName);
return null;
}
}
private List<String> parseRaidNames(SshCommand result) {
List<String> names = new ArrayList<>();
Arrays.stream(result.getResponse().split("\n"))
.map(line -> line.split(" "))
.filter(lineArray -> lineArray.length >= 2)
.map(lineArray -> lineArray[1])
.forEach(names::add);
return names;
}
private List<String> parseHddState(SshCommand result) {
List<String> names = new ArrayList<>();
names.add("Number Name State");
String[] lines = result.getResponse().split("\n");
boolean foundHeader = false;
for (String line : lines) {
if (!foundHeader) {
if ( line.contains("Number") &&
line.contains("Major") &&
line.contains("Minor") &&
line.contains("RaidDevice") ) {
foundHeader = true;
}
} else {
List<String> elements = Arrays.stream(line.split(" "))
.filter(x -> !Objects.equals(x, "")).toList();
names.add(elements.get(0) + ", "
+ elements.get(6) + ", "
+ elements.get(4) + " "
+ elements.get(5));
}
}
return names;
}
}

View File

@ -0,0 +1,39 @@
package ru.ldeloff.servermonitorbot.commands.hdd.temp.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.SshCommand;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
import ru.ldeloff.servermonitorbot.service.SshService;
import ru.ldeloff.servermonitorbot.view.ServerListButtons;
import java.util.Objects;
import java.util.Optional;
@Service
@Slf4j
public class HddTemp extends CommandTemplate {
public HddTemp(UpdateUtil updateUtil, ServerListButtons serverListButtons, SshService sshService, MessagingService messagingService) {
super(updateUtil, serverListButtons, sshService, messagingService);
setName("HDD.temp");
}
@Override
public String executeCommandSpecificHost(String serverName) {
Optional<SshServer> server = sshService.getAllSshServers()
.stream()
.filter(x -> x.getName().equals(serverName))
.findFirst();
if (server.isPresent()) {
SshCommand result = sshService.execute(new SshCommand("hddtemp /dev/sd*", 500, server.get()));
return server.get().getName() + ": \n" +
(Objects.isNull(result.getResponse()) ? "ошибка при выполнении команды" : result.getResponse());
} else {
log.error("Ошибка при выполнении команды 'hddtemp'. Искомый сервер (" + serverName + ") не найден");
return null;
}
}
}

View File

@ -0,0 +1,18 @@
package ru.ldeloff.servermonitorbot.commands.statuschecker.scheduler;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import ru.ldeloff.servermonitorbot.service.SshService;
@Service
@RequiredArgsConstructor
public class CheckSessionStatusScheduler {
private final SshService sshService;
@Scheduled(fixedRateString = "${ssh.checkConnectionDelay}")
public void updateSessionStatusCheck() {
sshService.updateConnection();
}
}

View File

@ -0,0 +1,28 @@
package ru.ldeloff.servermonitorbot.commands.statuschecker.service;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.service.SshService;
import ru.ldeloff.servermonitorbot.view.ServerListButtons;
@Service
public class CheckSessionStatus extends CommandTemplate {
public CheckSessionStatus(UpdateUtil updateUtil, ServerListButtons serverListButtons, SshService sshService, MessagingService messagingService) {
super(updateUtil, serverListButtons, sshService, messagingService);
setName("Статус");
}
public SendMessage executeAggregate(User user, SendMessage message) {
return super.sshService.getStatusSessions(message);
}
@Override
public String executeCommandSpecificHost(String serverName) {
return null;
}
}

View File

@ -0,0 +1,40 @@
package ru.ldeloff.servermonitorbot.commands.uname.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.SshCommand;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
import ru.ldeloff.servermonitorbot.service.SshService;
import ru.ldeloff.servermonitorbot.view.ServerListButtons;
import java.util.Objects;
import java.util.Optional;
@Service
@Slf4j
public class Uname extends CommandTemplate {
public Uname(UpdateUtil updateUtil, ServerListButtons serverListButtons, SshService sshService, MessagingService messagingService) {
super(updateUtil, serverListButtons, sshService, messagingService);
setName("uname");
}
@Override
public String executeCommandSpecificHost(String serverName) {
Optional<SshServer> server = sshService.getAllSshServers()
.stream()
.filter(x -> x.getName().equals(serverName))
.findFirst();
if (server.isPresent()) {
SshCommand result = sshService.execute(new SshCommand("uname -a", 100, server.get()));
return server.get().getName() + ": " +
(Objects.isNull(result.getResponse()) ? "ошибка при выполнении команды" : result.getResponse());
} else {
log.error("Ошибка при выполнении команды 'uname'. Искомый сервер ({}) не найден", serverName);
return null;
}
}
}

View File

@ -0,0 +1,38 @@
package ru.ldeloff.servermonitorbot.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.service.RoleService;
import java.util.List;
@Component
@ConfigurationProperties(prefix = "bot")
@Getter
@Setter
public class UserConfig {
private List<UserProperty> users;
@Autowired
private RoleService roleService;
@Getter
@Setter
public static class UserProperty {
private Long telegramId;
private String role;
}
public List<User> getUsers() {
return users.stream().map(user -> new User()
.setTelegramId(user.getTelegramId())
.setRole(roleService.findRoleByName(user.getRole()))
).toList();
}
}

View File

@ -0,0 +1,60 @@
package ru.ldeloff.servermonitorbot.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import ru.ldeloff.servermonitorbot.model.TelegramBot;
import ru.ldeloff.servermonitorbot.service.SshService;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.view.SwitchToMainMenu;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class TelegramBotController extends TelegramLongPollingBot {
private final Map<String, CommandTemplate> commands;
private final TelegramBot telegramBot;
private final SwitchToMainMenu switchToMainMenu;
private final SshService sshService;
@Override
public void onUpdateReceived(Update update) {
boolean result = false;
for (Map.Entry<String, CommandTemplate> entry : commands.entrySet()) {
result = entry.getValue().execute(update);
if (result) {
break;
}
}
if (!result) {
Message message = update.getMessage();
if (message!=null) {
message.setText("Not found");
}
update.setMessage(message);
switchToMainMenu.execute(update);
}
}
@Override
public String getBotUsername() {
return telegramBot.getBotUsername();
}
@Override
public String getBotToken() {
return telegramBot.getBotToken();
}
@Override
public void onClosing() {
super.onClosing();
sshService.disconnectAllConnections();
}
}

View File

@ -0,0 +1,26 @@
package ru.ldeloff.servermonitorbot.init;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import ru.ldeloff.servermonitorbot.config.UserConfig;
import ru.ldeloff.servermonitorbot.service.UserService;
@Slf4j
@Component
@RequiredArgsConstructor
@Order(2)
public class AddUsers implements ApplicationRunner {
final UserConfig userConfig;
final UserService userService;
@Override
public void run(ApplicationArguments args) {
userConfig.getUsers().forEach(userService::saveOrUpdateUser);
log.info("Загружены и обновлены пользователи");
}
}

View File

@ -0,0 +1,33 @@
package ru.ldeloff.servermonitorbot.init;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.service.UserService;
import ru.ldeloff.servermonitorbot.view.TelegramBotKeyboard;
@Slf4j
@Component
@RequiredArgsConstructor
@Order(3)
public class ReloadNotification implements ApplicationRunner {
private final TelegramBotKeyboard telegramBotKeyboard;
private final MessagingService messagingService;
private final UserService userService;
@Override
public void run(ApplicationArguments args) {
userService.getAllUsers().forEach(user -> {
SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(user.getTelegramId());
sendMessage.setText("Бот перезапущен");
messagingService.send(telegramBotKeyboard.uiForm(sendMessage));
});
}
}

View File

@ -0,0 +1,21 @@
package ru.ldeloff.servermonitorbot.init;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import ru.ldeloff.servermonitorbot.service.SshService;
@Component
@RequiredArgsConstructor
@Order(4)
public class SshConnect implements ApplicationRunner {
final SshService sshService;
@Override
public void run(ApplicationArguments args) {
sshService.updateConnection();
}
}

View File

@ -1,26 +1,24 @@
package ru.ldeloff.servermonitorbot;
package ru.ldeloff.servermonitorbot.init;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
import ru.ldeloff.servermonitorbot.model.TelegramBot;
import ru.ldeloff.servermonitorbot.controller.TelegramBotController;
@Slf4j
@Component
@NoArgsConstructor
@RequiredArgsConstructor
@Order(1)
public class StartBot implements ApplicationRunner {
private TelegramBot telegramBot;
@Autowired
public StartBot(TelegramBot telegramBot) {
this.telegramBot = telegramBot;
}
private final TelegramBotController telegramBot;
@Override
public void run(ApplicationArguments args) {
@ -29,7 +27,6 @@ public class StartBot implements ApplicationRunner {
botsApi.registerBot(telegramBot);
log.info("Бот запущен");
} catch (TelegramApiException e) {
e.printStackTrace();
log.error(e.getMessage());
}
}

View File

@ -0,0 +1,26 @@
package ru.ldeloff.servermonitorbot.model;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
@Getter
@Setter
public class SshCommand {
@NotNull
private String command;
@NotNull
@Min(100)
private int timeout;
@NotNull
private SshServer sshServer;
private String response;
public SshCommand(String command, int timeout, SshServer sshServer) {
this.command = command;
this.timeout = timeout;
this.sshServer = sshServer;
}
}

View File

@ -1,47 +1,17 @@
package ru.ldeloff.servermonitorbot.model;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
@Getter
@Component
@NoArgsConstructor
@AllArgsConstructor
public class TelegramBot extends TelegramLongPollingBot {
@Value("${bot.name}")
private String botUsername;
public class TelegramBot{
private final String botUsername;
private final String botToken;
@Value("${bot.token}")
private String botToken;
@Override
public void onUpdateReceived(Update update) {
// We check if the update has a message and the message has text
if (update.hasMessage() && update.getMessage().hasText()) {
SendMessage message = new SendMessage(); // Create a SendMessage object with mandatory fields
message.setChatId(update.getMessage().getChatId().toString());
message.setText(update.getMessage().getText());
try {
execute(message); // Call method to send the message
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
@Override
public String getBotUsername() {
return botUsername;
}
@Override
public String getBotToken() {
return botToken;
public TelegramBot(@Value("${bot.name}") String botUsername, @Value("${bot.token}") String botToken) {
this.botUsername = botUsername;
this.botToken = botToken;
}
}

View File

@ -0,0 +1,7 @@
package ru.ldeloff.servermonitorbot.model.server;
public enum ServerStatus {
ONLINE,
OFFLINE,
CONNECTION_LOST
}

View File

@ -0,0 +1,25 @@
package ru.ldeloff.servermonitorbot.model.server;
import com.jcraft.jsch.Session;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Component;
@Setter
@Getter
@Component
public class SshServer {
@NotNull
private String name;
@NotNull
private String host;
@NotNull
private int port;
@NotNull
private String user;
@NotNull
private String password;
private Session session;
private ServerStatus status;
}

View File

@ -0,0 +1,16 @@
package ru.ldeloff.servermonitorbot.model.server;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.List;
@Configuration
@ConfigurationProperties(prefix = "ssh")
@Getter
@Setter
public class SshServers {
private List<SshServer> servers;
}

View File

@ -0,0 +1,7 @@
package ru.ldeloff.servermonitorbot.model.user;
public enum Role {
ADMIN,
USER,
ANONYMOUS
}

View File

@ -0,0 +1,12 @@
package ru.ldeloff.servermonitorbot.model.user;
import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class User {
private Long telegramId;
private Role role;
private String login;
}

View File

@ -0,0 +1,13 @@
package ru.ldeloff.servermonitorbot.model.user;
import lombok.Getter;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Getter
@Component
public class Users {
private final List<User> users = new ArrayList<>();
}

View File

@ -0,0 +1,12 @@
package ru.ldeloff.servermonitorbot.repository;
import com.jcraft.jsch.JSchException;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
public interface SshRepository {
void connect(SshServer sshServer) throws JSchException;
void disconnect(SshServer sshServer);
}

View File

@ -0,0 +1,37 @@
package ru.ldeloff.servermonitorbot.repository;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
@Repository
@RequiredArgsConstructor
public class SshRepositoryImpl implements SshRepository {
@Value("${ssh.timeout:5000}")
private int TIMEOUT;
@Override
public void connect(SshServer sshServer) throws JSchException {
Session session = new JSch().getSession(sshServer.getUser(),
sshServer.getHost(),
sshServer.getPort());
session.setPassword(sshServer.getPassword());
session.setConfig("StrictHostKeyChecking", "no");
session.setTimeout(TIMEOUT);
session.connect();
sshServer.setSession(session);
}
@Override
public void disconnect(SshServer sshServer) {
sshServer.getSession().disconnect();
}
}

View File

@ -0,0 +1,11 @@
package ru.ldeloff.servermonitorbot.service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
public interface MessagingService {
void sendMessageToAll(String message);
void sendMessageToAdmins(String message);
void send(SendMessage message);
}

View File

@ -0,0 +1,48 @@
package ru.ldeloff.servermonitorbot.service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import ru.ldeloff.servermonitorbot.controller.TelegramBotController;
@Slf4j
@Service
@RequiredArgsConstructor
public class MessagingServiceImpl implements MessagingService {
private final UserService userService;
private final ApplicationContext applicationContext;
@Override
public void sendMessageToAll(String message) {
userService.getAllUsers().forEach(user -> {
SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(user.getTelegramId());
sendMessage.setText(message);
send(sendMessage);
});
}
@Override
public void sendMessageToAdmins(String message) {
userService.getAllAdmins().forEach(user -> {
SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(user.getTelegramId());
sendMessage.setText(message);
send(sendMessage);
});
}
@Override
public void send(SendMessage message) {
try {
applicationContext.getBean(TelegramBotController.class).execute(message);
} catch (TelegramApiException e) {
log.warn("Ошибка при отправке сообщения", e.getMessage());
}
}
}

View File

@ -0,0 +1,7 @@
package ru.ldeloff.servermonitorbot.service;
import ru.ldeloff.servermonitorbot.model.user.Role;
public interface RoleService {
Role findRoleByName(String name);
}

View File

@ -0,0 +1,14 @@
package ru.ldeloff.servermonitorbot.service;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import ru.ldeloff.servermonitorbot.model.user.Role;
@Service
@RequiredArgsConstructor
public class RoleServiceImpl implements RoleService {
@Override
public Role findRoleByName(String name) {
return Role.valueOf(name);
}
}

View File

@ -0,0 +1,25 @@
package ru.ldeloff.servermonitorbot.service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import ru.ldeloff.servermonitorbot.model.SshCommand;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
import java.util.List;
public interface SshService {
void updateConnection();
void disconnectAllConnections();
SendMessage getStatusSessions(SendMessage update);
List<SshServer> getAllSshServers();
List<SshServer> getHealthSshServers();
SshCommand execute(SshCommand sshCommand);
List<SshCommand> execute(List<SshCommand> sshCommands);
}

View File

@ -0,0 +1,146 @@
package ru.ldeloff.servermonitorbot.service;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import ru.ldeloff.servermonitorbot.model.server.ServerStatus;
import ru.ldeloff.servermonitorbot.model.server.SshServers;
import ru.ldeloff.servermonitorbot.model.SshCommand;
import ru.ldeloff.servermonitorbot.model.server.SshServer;
import ru.ldeloff.servermonitorbot.repository.SshRepository;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Service
@Slf4j
@RequiredArgsConstructor
public class SshServiceImpl implements SshService {
private final SshServers sshServers;
private final SshRepository sshRepository;
private final MessagingService messagingService;
@Override
public void updateConnection() {
sshServers.getServers().forEach(sshServer -> {
try {
sshRepository.connect(sshServer);
updateServerStatus(sshServer, ServerStatus.ONLINE);
log.info("Успешно подключён к {}", sshServer.getHost());
} catch (JSchException e) {
if (sshServer.getStatus() == null) {
updateServerStatus(sshServer, ServerStatus.OFFLINE);
}
if (sshServer.getStatus() == ServerStatus.ONLINE) {
updateServerStatus(sshServer, ServerStatus.CONNECTION_LOST);
}
log.warn("Не удалось соединиться с {}: {}", sshServer.getHost(), e.getMessage());
}
});
}
@Override
public void disconnectAllConnections() {
sshServers.getServers().forEach(sshRepository::disconnect);
}
@Override
public SendMessage getStatusSessions(SendMessage message) {
StringBuilder text = new StringBuilder("Статус соединения (может выполняться долго): \n");
sshServers.getServers().forEach(server -> text.append(server.getName())
.append(": ")
.append(checkStatusServer(server))
.append("\n"));
message.setText(text.toString());
return message;
}
private String checkStatusServer(SshServer server) {
if (Objects.isNull(server.getSession())) {
return "нет соединения";
}
if (server.getSession().isConnected()) {
return "OK";
} else {
return "потеряно соединение";
}
}
private boolean checkHealth(SshServer server) {
if (Objects.isNull(server.getSession())) {
return false;
}
return server.getSession().isConnected();
}
@Override
public List<SshServer> getAllSshServers() {
return sshServers.getServers();
}
@Override
public List<SshServer> getHealthSshServers() {
return sshServers.getServers().stream().filter(this::checkHealth).toList();
}
@Override
public SshCommand execute(SshCommand sshCommand) {
List<SshCommand> sshCommands = new ArrayList<>();
sshCommands.add(sshCommand);
return execute(sshCommands).get(0);
}
@Override
public List<SshCommand> execute(List<SshCommand> sshCommands) {
Session session = sshCommands.get(0).getSshServer().getSession(); // подразумевается, что в листе с командами сервер один и тот же
ChannelExec channel = null;
try {
channel = (ChannelExec) session.openChannel("exec");
ChannelExec finalChannel = channel;
sshCommands.forEach(command -> {
try {
finalChannel.setCommand(command.getCommand());
ByteArrayOutputStream responseStream = new ByteArrayOutputStream();
finalChannel.setOutputStream(responseStream);
finalChannel.connect();
while (finalChannel.isConnected()) {
Thread.sleep(command.getTimeout());
}
String responseString = new String(responseStream.toByteArray());
command.setResponse(responseString);
} catch (JSchException | InterruptedException e) {
log.warn(e.getMessage());
throw new RuntimeException(e);
}
});
} catch (JSchException e) {
log.warn(e.getMessage());
throw new RuntimeException(e);
} finally {
if (channel != null) {
channel.disconnect();
}
}
return sshCommands;
}
public void updateServerStatus(SshServer server, ServerStatus newStatus) {
ServerStatus oldStatus = server.getStatus();
if (oldStatus != newStatus) {
server.setStatus(newStatus);
messagingService.sendMessageToAdmins("Server status changed for " + server.getName() +
": " + oldStatus + " -> " + newStatus);
}
}
}

View File

@ -0,0 +1,16 @@
package ru.ldeloff.servermonitorbot.service;
import ru.ldeloff.servermonitorbot.model.user.User;
import java.util.List;
public interface UserService {
void saveOrUpdateUser(User user);
User getByTelegramId(Long id);
List<User> getAllUsers();
List<User> getAllAdmins();
}

View File

@ -0,0 +1,42 @@
package ru.ldeloff.servermonitorbot.service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import ru.ldeloff.servermonitorbot.model.user.Role;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.model.user.Users;
import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
private final Users users;
@Override
public void saveOrUpdateUser(User user) {
if (getByTelegramId(user.getTelegramId()) == null) {
users.getUsers().add(user);
}
}
@Override
public User getByTelegramId(Long telegramId) {
return users.getUsers().stream()
.filter(user -> user.getTelegramId().equals(telegramId))
.findFirst()
.orElse(null);
}
@Override
public List<User> getAllUsers() {return users.getUsers(); }
@Override
public List<User> getAllAdmins() {
return users.getUsers().stream().filter(user -> user.getRole().equals(Role.ADMIN)).toList();
}
}

View File

@ -0,0 +1,51 @@
package ru.ldeloff.servermonitorbot.util;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.objects.Update;
import ru.ldeloff.servermonitorbot.model.user.Role;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.service.UserService;
import java.util.List;
@Service
@RequiredArgsConstructor
public class UpdateUtil {
private final UserService userService;
public User getUser(Update update) {
long id = -1L;
String login = null;
if (update.hasMessage()) {
id = update.getMessage().getChat().getId();
login = update.getMessage().getChat().getUserName();
} else if (update.hasCallbackQuery()) {
id = update.getCallbackQuery().getMessage().getChatId();
login = update.getCallbackQuery().getFrom().getUserName();
}
User user = userService.getByTelegramId(id);
if (user == null) {
user = new User();
user.setTelegramId(id);
user.setRole(Role.ANONYMOUS);
}
user.setLogin(login);
return user;
}
public String getMessage(Update update) {
if (update.hasMessage()) {
return update.getMessage().getText();
} else if (update.hasCallbackQuery()) {
return update.getCallbackQuery().getData();
}
return "";
}
public boolean roleChecker(Update update, List<Role> expectedRoles) {
User user = getUser(update);
return expectedRoles.contains(user.getRole());
}
}

View File

@ -0,0 +1,33 @@
package ru.ldeloff.servermonitorbot.view;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.service.SshService;
@Service
public class FirstUseCommand extends CommandTemplate {
private final TelegramBotKeyboard telegramBotKeyboard;
public FirstUseCommand(UpdateUtil updateUtil, ServerListButtons serverListButtons, SshService sshService, TelegramBotKeyboard telegramBotKeyboard, MessagingService messagingService) {
super(updateUtil, serverListButtons, sshService, messagingService);
this.telegramBotKeyboard = telegramBotKeyboard;
setName("/start");
}
@Override
public SendMessage executeAggregate(User user, SendMessage message) {
message.setText("Добро пожаловать " + user.getLogin() + "!");
return telegramBotKeyboard.uiForm(message);
}
@Override
public String executeCommandSpecificHost(String serverName) {
return null;
}
}

View File

@ -0,0 +1,53 @@
package ru.ldeloff.servermonitorbot.view;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import ru.ldeloff.servermonitorbot.service.SshService;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Component
@RequiredArgsConstructor
public class ServerListButtons implements UiFormer {
private final SshService sshService;
@Override
public SendMessage uiForm(SendMessage message) {
List<List<InlineKeyboardButton>> keyboard = new ArrayList<>();
InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
sshService.getAllSshServers().forEach(sshServer -> {
if (Objects.nonNull(sshServer.getSession())) {
if (sshServer.getSession().isConnected()) {
List<InlineKeyboardButton> keyboardRow = new ArrayList<>();
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(sshServer.getName());
inlineKeyboardButton.setCallbackData(message.getText() + ": " + sshServer.getName());
keyboardRow.add(inlineKeyboardButton);
keyboard.add(keyboardRow);
}
}
});
if (keyboard.size() > 1) {
List<InlineKeyboardButton> keyboardRow = new ArrayList<>();
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText("Все сервера");
inlineKeyboardButton.setCallbackData(message.getText() + ": all");
keyboardRow.add(inlineKeyboardButton);
keyboard.add(keyboardRow);
}
inlineKeyboardMarkup.setKeyboard(keyboard);
message.setReplyMarkup(inlineKeyboardMarkup);
message.setText("Выполнить " + message.getText() + " для");
return message;
}
}

View File

@ -0,0 +1,37 @@
package ru.ldeloff.servermonitorbot.view;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import ru.ldeloff.servermonitorbot.service.MessagingService;
import ru.ldeloff.servermonitorbot.util.UpdateUtil;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.service.SshService;
@Service
@Slf4j
public class SwitchToMainMenu extends CommandTemplate {
private final TelegramBotKeyboard telegramBotKeyboard;
public SwitchToMainMenu(UpdateUtil updateUtil, ServerListButtons serverListButtons, SshService sshService, TelegramBotKeyboard telegramBotKeyboard, MessagingService messagingService) {
super(updateUtil, serverListButtons, sshService, messagingService);
this.telegramBotKeyboard = telegramBotKeyboard;
setName("Not found");
}
@Override
public String executeCommandSpecificHost(String serverName) {
return null;
}
@Override
public SendMessage executeAggregate(User user, SendMessage message) {
SendMessage answer = new SendMessage();
answer.setChatId(user.getTelegramId());
answer.setText("Неверная команда. Попробуем сначала.");
return telegramBotKeyboard.uiForm(answer);
}
}

View File

@ -0,0 +1,70 @@
package ru.ldeloff.servermonitorbot.view;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardButton;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
import ru.ldeloff.servermonitorbot.model.user.Role;
import ru.ldeloff.servermonitorbot.model.user.User;
import ru.ldeloff.servermonitorbot.service.UserService;
import ru.ldeloff.servermonitorbot.commands.CommandTemplate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static ru.ldeloff.servermonitorbot.model.user.Role.ADMIN;
import static ru.ldeloff.servermonitorbot.model.user.Role.USER;
@Component
@RequiredArgsConstructor
public class TelegramBotKeyboard implements UiFormer {
private final UserService userService;
private final ApplicationContext applicationContext;
@Override
public SendMessage uiForm(SendMessage message) {
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboard(false);
String chatId = message.getChatId();
User user = userService.getByTelegramId(Long.parseLong(chatId));
ArrayList<KeyboardRow> keyboardRows = formKeyboard(user);
replyKeyboardMarkup.setKeyboard(keyboardRows);
message.setReplyMarkup(replyKeyboardMarkup);
return message;
}
private ArrayList<KeyboardRow> formKeyboard(User user) {
Role role = user.getRole();
Map<String, CommandTemplate> commands = applicationContext.getBeansOfType(CommandTemplate.class);
commands.remove("firstUseCommand");
commands.remove("switchToMainMenu");
int buttonOnLine = 3;
ArrayList<KeyboardRow> keyboardRows = new ArrayList<>();
KeyboardRow keyboardRow = new KeyboardRow();
for (Map.Entry<String, CommandTemplate> entry : commands.entrySet()) {
if (entry.getValue().getExpectedRole().contains(role)) {
keyboardRow.add(new KeyboardButton(entry.getValue().getName()));
}
if (keyboardRow.size()>=buttonOnLine) {
keyboardRows.add(keyboardRow);
keyboardRow = new KeyboardRow();
}
}
if (!keyboardRow.isEmpty()) {
keyboardRows.add(keyboardRow);
}
return keyboardRows;
}
}

View File

@ -0,0 +1,7 @@
package ru.ldeloff.servermonitorbot.view;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
public interface UiFormer {
SendMessage uiForm(SendMessage message);
}

View File

@ -1,5 +1,28 @@
spring:
application:
name: ServerMonitorBot
bot:
name: "ServerMonitorBot"
token: "token"
users:
- telegramId: 123456789
role: admin
ssh:
checkConnectionDelay: 300000
timeout: 5000
servers:
-
name: "Server Name"
host: "url"
port: 22
user: "user"
password: "pass"
-
name: "Server Name 2"
host: "url 2"
port: 22
user: "user 2"
password: "pass 2"