Skip to content

Commit

Permalink
optim agent service and no choice of plugins in ui install
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-christophe81 committed Dec 11, 2024
1 parent ee48381 commit 25d517c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 56 deletions.
116 changes: 63 additions & 53 deletions agent/installer/centreon-monitoring-agent.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ VIAddVersionKey "ProductVersion" "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD

InstallDir "$PROGRAMFILES64\${COMPANYNAME}\${APPNAME}"
!define PLUGINS_DIR "$PROGRAMFILES64\${COMPANYNAME}\Plugins"
!define PLUGINS_FULL_PATH "${PLUGINS_DIR}\centreon_plugins.exe"

!define HELPURL "https://www.centreon.com/"

Var plugins_url
Var plugin_section_choice

Var plugins_download_failure


!macro verify_user_is_admin
Expand Down Expand Up @@ -127,20 +127,17 @@ Function get_plugins_url
ClearErrors
inetc::get /header "Accept: application/vnd.github+json" ${NSCLIENT_URL} $json_content_path /End
${If} ${Errors}
MessageBox MB_OK|MB_ICONSTOP "Failed to get plugin information from ${NSCLIENT_URL}"
Abort
MessageBox MB_YESNO "Failed to get plugin information from ${NSCLIENT_URL} .$\nDo you want to install centreon plugins version ${PLUGINS_VERSION}?" /SD IDYES IDYES continue_with_embedded_plugins IDNO continue_without_plugins
${EndIf}
Pop $0
${If} $0 != "OK"
MessageBox MB_OK|MB_ICONSTOP "Failed to get plugin information from ${NSCLIENT_URL}: $0"
Abort
MessageBox MB_YESNO "Failed to get plugin information from ${NSCLIENT_URL}: $0 $\nDo you want to install centreon plugins version ${PLUGINS_VERSION}?" /SD IDYES IDYES continue_with_embedded_plugins IDNO continue_without_plugins
${EndIf}

#parse json response
nsJSON::Set /file $json_content_path
${If} ${Errors}
MessageBox MB_OK|MB_ICONSTOP "bad json received from ${NSCLIENT_URL}"
Abort
MessageBox MB_YESNO "Bad json received from ${NSCLIENT_URL} $\nDo you want to install centreon plugins version ${PLUGINS_VERSION}?" /SD IDYES IDYES continue_with_embedded_plugins IDNO continue_without_plugins
${EndIf}

nsJSON::Get /count `assets` /end
Expand All @@ -159,31 +156,72 @@ Function get_plugins_url
${EndIf}
${Next}

MessageBox MB_OK|MB_ICONSTOP "No Plugins Asset found at ${NSCLIENT_URL}"
Abort
MessageBox MB_YESNO "No Plugins Asset found at ${NSCLIENT_URL} $\nDo you want to install centreon plugins version ${PLUGINS_VERSION}?" /SD IDYES IDYES continue_with_embedded_plugins IDNO continue_without_plugins
continue_without_plugins:
StrCpy $plugins_download_failure 2
Return
continue_with_embedded_plugins:
StrCpy $plugins_download_failure 1
Return

FunctionEnd

/**
* @brief this section download plugings from the asset of the last centreon-nsclient-build release
*/
Section "Download latest Centreon Plugins" PluginsInstSection
Call get_plugins_url
Section "Plugins" PluginsInstSection
CreateDirectory ${PLUGINS_DIR}
DetailPrint "download plugins from $plugins_url"
inetc::get /caption "plugins" /banner "Downloading plugins..." "$plugins_url" "${PLUGINS_DIR}/centreon_plugins.exe"
${If} ${Silent}
System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console
System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout
FileWrite $0 "Centreon plugins installed$\n"
${EndIf}
SectionEnd

${IfNot} ${Silent}
Call get_plugins_url
${If} $plugins_download_failure == 1
DetailPrint "Install centreon plugins version ${PLUGINS_VERSION}"
File /oname=${PLUGINS_FULL_PATH} "centreon_plugins.exe"
${ElseIf} $plugins_download_failure == 2
DetailPrint 'centreon plugins not installed'
${Else}
DetailPrint "download plugins from $plugins_url"
ClearErrors
inetc::get /caption "plugins" /banner "Downloading plugins..." "$plugins_url" "${PLUGINS_DIR}/centreon_plugins.exe"
${If} ${Errors}
MessageBox MB_YESNO "Fail to download plugins $\nDo you want to install centreon plugins version ${PLUGINS_VERSION}?" /SD IDYES IDYES ui_continue_with_embedded_plugins IDNO ui_continue_without_plugins
ui_continue_with_embedded_plugins:
DetailPrint "Install centreon plugins version ${PLUGINS_VERSION}"
File /oname=${PLUGINS_FULL_PATH} "centreon_plugins.exe"
ui_continue_without_plugins:
DetailPrint 'centreon plugins not installed'
${EndIf}
${EndIf}

${Else}
${If} $silent_install_plugins == 2
File /oname=${PLUGINS_FULL_PATH} "centreon_plugins.exe"
System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console
System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout
FileWrite $0 "Centreon plugins version ${PLUGINS_VERSION} installed$\n"
${Else}
Call get_plugins_url
${If} $plugins_download_failure > 0
File /oname=${PLUGINS_FULL_PATH} "centreon_plugins.exe"
System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console
System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout
FileWrite $0 "Fail to download plugins => Centreon plugins version ${PLUGINS_VERSION} installed$\n"
${Else}
ClearErrors
inetc::get /caption "plugins" /banner "Downloading plugins..." "$plugins_url" "${PLUGINS_DIR}/centreon_plugins.exe"
${If} ${Errors}
File /oname=${PLUGINS_FULL_PATH} "centreon_plugins.exe"
System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console
System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout
FileWrite $0 "Fail to download plugins => Centreon plugins version ${PLUGINS_VERSION} installed$\n"
${Else}
System::Call 'kernel32::AttachConsole(i -1)i.r0' ;attach to parent console
System::Call 'kernel32::GetStdHandle(i -11)i.r0' ;console attached -- get stdout
FileWrite $0 "Centreon plugins installed$\n"
${EndIf}
${EndIf}
${EndIf}
${EndIf}

Section /o "Centreon Plugins ${PLUGINS_VERSION}" PluginsEmbeddedInstSection
SetOutPath ${PLUGINS_DIR}
File "centreon_plugins.exe"
SectionEnd

/**
Expand Down Expand Up @@ -265,44 +303,16 @@ function .onInit
SectionSetFlags ${CMAInstSection} 0
${EndIf}

${If} $silent_install_plugins == 1
${If} $silent_install_plugins > 0
SectionSetFlags ${PluginsInstSection} ${SF_SELECTED}
SectionSetFlags ${PluginsEmbeddedInstSection} 0
${ElseIf} $silent_install_plugins == 2
SectionSetFlags ${PluginsInstSection} 0
SectionSetFlags ${PluginsEmbeddedInstSection} ${SF_SELECTED}
${Else}
SectionSetFlags ${PluginsInstSection} 0
SectionSetFlags ${PluginsEmbeddedInstSection} 0
${EndIf}

${Else}
#by default download plugins
StrCpy $plugin_section_choice ${PluginsInstSection}
${EndIf}

functionEnd

Function .onSelChange
#only one plugins component can be selected
${If} ${SectionIsSelected} ${PluginsInstSection}
${AndIf} ${SectionIsSelected} ${PluginsEmbeddedInstSection}
Push $0
${If} $plugin_section_choice == ${PluginsInstSection}
SectionGetFlags ${PluginsInstSection} $0
IntOp $0 $0 & ${${SECTION_OFF}}
SectionSetFlags ${PluginsInstSection} $0
StrCpy $plugin_section_choice ${PluginsEmbeddedInstSection}
${Else}
SectionGetFlags ${PluginsEmbeddedInstSection} $0
IntOp $0 $0 & ${${SECTION_OFF}}
SectionSetFlags ${PluginsEmbeddedInstSection} $0
StrCpy $plugin_section_choice ${PluginsInstSection}
${EndIf}
Pop $0
${EndIf}
FunctionEnd

/**
* @brief show cma setup dialogbox ig user has choosen to install cma
*/
Expand Down
2 changes: 1 addition & 1 deletion agent/installer/dlg_helper.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Function init_log_dlg
${NSD_CB_SelectString} $hCtl_log_dlg_log_level $0
ReadRegStr $0 HKLM ${CMA_REG_KEY} "log_type"
${If} $0 == ""
StrCpy $0 "EventLog"
StrCpy $0 "Event-Log"
${EndIf}
${NSD_CB_SelectString} $hCtl_log_dlg_log_type $0
ReadRegDWORD $0 HKLM ${CMA_REG_KEY} "log_max_file_size"
Expand Down
4 changes: 3 additions & 1 deletion agent/installer/silent.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Function cmd_line_to_registry
${EndIf}

${Else}
WriteRegStr HKLM ${CMA_REG_KEY} "log_type" "EventLog"
WriteRegStr HKLM ${CMA_REG_KEY} "log_type" "event-log"
${EndIf}
ClearErrors
${GetOptions} $cmdline_parameters "--log_level" $0
Expand Down Expand Up @@ -299,6 +299,8 @@ Function silent_update_conf
${Else}
WriteRegStr HKLM ${CMA_REG_KEY} "log_type" "event-log"
${EndIf}
${Else}
WriteRegStr HKLM ${CMA_REG_KEY} "log_type" "event-log"
${EndIf}
ReadRegStr $0 HKLM ${CMA_REG_KEY} "log_type"
${If} $0 == "file"
Expand Down
2 changes: 1 addition & 1 deletion agent/native_windows/src/check_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void service_enumerator::_enumerate_services(
if (success || GetLastError() == ERROR_MORE_DATA) {
LPENUM_SERVICE_STATUSA services_end = services + services_count;
for (LPENUM_SERVICE_STATUS serv = services; serv < services_end; ++serv) {
if (start_auto) {
if constexpr (start_auto) {
QUERY_SERVICE_CONFIGA serv_conf;
if (!_query_service_config(serv->lpServiceName, serv_conf, logger)) {
continue;
Expand Down

0 comments on commit 25d517c

Please sign in to comment.