{"id":394,"date":"2023-08-02T09:22:29","date_gmt":"2023-08-02T07:22:29","guid":{"rendered":"https:\/\/whoami.lausitz-event.info\/?p=394"},"modified":"2023-08-02T09:26:14","modified_gmt":"2023-08-02T07:26:14","slug":"automatischer-neustart-von-windows-diensten-durch-icinga2","status":"publish","type":"post","link":"https:\/\/whoami.lausitz-event.info\/?p=394","title":{"rendered":"Automatischer Neustart von Windows Diensten durch Icinga2"},"content":{"rendered":"\n\n<p>Das mit Icinga2 Windows Dienste \u00fcberwacht werden ist nichts neues. Es gibt aber auch Dienste welche aufgrund der Systemumgebung oder \"schlechter\" Programmierung von Zeit zu Zeit abst\u00fcrzen. Da w\u00e4re es doch eine coole Sache wenn unser Monitoring im Fehlerfall den Dienst automatisiert neu starten k\u00f6nnte. Dazu sind die folgenden Schritte notwendig.<\/p>\n\n\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@localhost]#dnf install samba-common-tools<\/code><\/pre>\n\n\n\n\n\n<p><strong>\/usr\/lib64\/nagios\/plugins\/restart_win_service.sh<\/strong><\/p>\n\n\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n#\n# restarts a remote windows service via rpc\nUSER_ID=USERNAME\nUSER_PASSWORD=PASSWORD\n# define usage function\nusage()\n    {\n        echo \"usage $0 (-h &lt;help>) -H &lt;host_address> -u &lt;user_id> -p &lt;user_password> -n &lt;service_name> -s &lt;service_state_id>\"\n    }\n\n# exit when option string does not begin with a '-'\nif &#91;&#91; ! $@ =~ ^\\-.+ ]]\nthen\n  usage\nfi\n\n# execute getopt on the arguments passed to this program, identified by the special character $@\nOPTS=$(getopt -n \"$0\" -o hH:u:p:n:s: -- \"$@\")\n\n# bad arguments, something has gone wrong with the getopt command.\nif &#91; $? -ne 0 ];\nthen\n    exit 1\nfi\n\n# little magic, necessary when using getopt.\neval set -- \"$OPTS\"\n\n# Now goes through all the options with a case and using shift to analyse 1 argument at a time.\n# $1 identifies the first argument, and when we use shift we discard the first argument, so $2 becomes $1 and goes again through the case.\n# go through all options\nwhile true;\ndo\n    case \"$1\" in\n        -h)\n            usage\n            shift;;\n        -H)\n            # We need to take the option of the argument \"-h\"\n            HOST_ADDRESS=$2\n            shift 2;;\n        -u)\n            USER_ID=$2\n            shift 2;;\n        -p)\n            USER_PASSWORD=$2\n            shift 2;;\n        -n)\n            SERVICE_NAME=$2\n            shift 2;;\n        -s)\n            SERVICE_STATE_ID=$2\n            shift 2;;\n        --)\n            shift\n            break;;\n    esac\ndone\n\nif &#91; ! $SERVICE_STATE_ID == 0 ]\nthen\n    net rpc service start \"$SERVICE_NAME\" -I $HOST_ADDRESS -U \"$USER_ID%$USER_PASSWORD\" > \/dev\/null 2> \/dev\/null\nfi\n<\/code><\/pre>\n\n\n\n\n\n<p>Im Icinga Director muss ein Kommando als <em>Event Plugin Command<\/em> angelegt werden. Daf\u00fcr sind die Datenfelder Anmeldename, Passwort, Servicename und Service State zu definieren.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Das mit Icinga2 Windows Dienste \u00fcberwacht werden ist nichts neues. Es gibt aber auch Dienste welche aufgrund der Systemumgebung oder \"schlechter\" Programmierung von Zeit zu Zeit abst\u00fcrzen. Da w\u00e4re es doch eine coole Sache wenn unser Monitoring im Fehlerfall den Dienst automatisiert neu starten k\u00f6nnte. Dazu sind die folgenden Schritte notwendig. \/usr\/lib64\/nagios\/plugins\/restart_win_service.sh Im Icinga Director [&hellip;]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[9,3],"tags":[],"class_list":["post-394","post","type-post","status-publish","format-standard","hentry","category-icinga","category-it"],"_links":{"self":[{"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=\/wp\/v2\/posts\/394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=394"}],"version-history":[{"count":3,"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":397,"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=\/wp\/v2\/posts\/394\/revisions\/397"}],"wp:attachment":[{"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/whoami.lausitz-event.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}