### Get a list of installed software on a Windows machine Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_WMI.htm?TocPath=%D0%A1%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D1%8B%D0%B5+%D1%81%D1%86%D0%B5%D0%BD%D0%B0%D1%80%D0%B8%D0%B8.+DAP%7C%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B+API.+DAP%7C%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81%C2%A0%D0%BF%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%D0%BC%D0%B8.+DAP%7C_____8 This example demonstrates how to retrieve a list of installed software by querying the registry. ```groovy def list = []; endpoint.openRegistry({ registry -> registry.openHKLM({ handle -> handle.open("Software\Microsoft\Windows\CurrentVersion\Uninstall", api.wmi.KEY_ALL_ACCESS, { rootNode -> rootNode.getKeys().keySet().each { nodeName -> handle.open("Software\Microsoft\Windows\CurrentVersion\Uninstall\" + nodeName, api.wmi.KEY_ALL_ACCESS, { softwareNode -> list.add(softwareNode.getValues().collectEntries { k, v -> [(k): softwareNode.query(k)] }) }) } }) }) }) return list ``` -------------------------------- ### Getting a List of ESXi Hosts Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to retrieve a list of all ESXi host objects. ```Groovy endpoint.getObjectsByType('HostSystem') ``` -------------------------------- ### Getting a List of Virtual Machines Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to retrieve a list of all virtual machine objects. ```Groovy endpoint.getObjectsByType('VirtualMachine') ``` -------------------------------- ### Start NDAP Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/instal_dap_Linux.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0+NDAP%7C_____3 Command to start the NDAP service. ```bash sudo systemctl start ndap.service ``` -------------------------------- ### Delete a registry key Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_WMI.htm?TocPath=%D0%A1%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D1%8B%D0%B5+%D1%81%D1%86%D0%B5%D0%BD%D0%B0%D1%80%D0%B8%D0%B8.+DAP%7C%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B+API.+DAP%7C%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81%C2%A0%D0%BF%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%D0%BC%D0%B8.+DAP%7C_____8 This example demonstrates how to delete a registry key. ```groovy endpoint.openRegistry({registry-> registry.openHKLM({ handle -> handle.open("Software\Microsoft\Windows\CurrentVersion\Uninstall\test", api.wmi.KEY_ALL_ACCESS, { rootNode-> rootNode.delete("childNode", true) }) }) }) ``` -------------------------------- ### Start NDAP service Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/instal_dap_Win.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0+NDAP%7C_____4 Command to start the NDAP service. ```PowerShell Start-Service -name ndap ``` -------------------------------- ### Getting All Available Alarms Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to retrieve a list of all available alarms for all objects. ```Groovy endpoint.getAlarm() ``` -------------------------------- ### Get hosts from Zabbix using an API token Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_Zabbix.htm This example shows how to obtain an API token using login credentials and then use that token to call the 'host.get' method to retrieve host information. ```Groovy apiToken = endpoint.login('zabbixLogin', 'zabbixPassword') endpoint.call('host.get', ['output' : ['hostid','host'], 'selectInterfaces' : ['interfaceid','ip']], apiToken) ``` -------------------------------- ### Enable service auto-start Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/instal_dap_Linux.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0+NDAP%7C_____3 Enables the NDAP service to start automatically on server boot. ```bash sudo systemctl enable ndap.service ``` -------------------------------- ### Variable Definition and Usage in Log4j2 Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/log4j2Properties.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%9A%D0%BE%D0%BD%D1%84%D0%B8%D0%B3%D1%83%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C_____2 This example shows how to define and use variables within the log4j2 configuration file. ```properties property.%ИМЯ ПЕРЕМЕННОЙ%=%ЗНАЧЕНИЕ ПЕРЕМЕННОЙ% ... %ПАРАМЕТР%=${%ИМЯ ПЕРЕМЕННОЙ%} ``` -------------------------------- ### Create a child registry key Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_WMI.htm?TocPath=%D0%A1%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D1%8B%D0%B5+%D1%81%D1%86%D0%B5%D0%BD%D0%B0%D1%80%D0%B8%D0%B8.+DAP%7C%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B+API.+DAP%7C%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81%C2%A0%D0%BF%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%D0%BC%D0%B8.+DAP%7C_____8 This example shows how to create a child registry key with specified access rights and options. ```groovy endpoint.openRegistry({ registry -> registry.openHKLM({ handle -> handle.open("Software\Microsoft\Windows\CurrentVersion\Uninstall\test", api.wmi.KEY_ALL_ACCESS, { rootNode -> rootNode.create("childNode", api.wmi.REG_OPTION_NON_VOLATILE, api.wmi.KEY_ALL_ACCESS, { newNode -> // Здесь можно выполнить операции с разделом }) }) }) }) ``` -------------------------------- ### Пример 1. Выполнение SQL-запроса на выборку количества строк в таблице tbl_example. Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_JDBC.htm Получение объекта соединения с базой данных и выполнение SQL-запроса на выборку количества строк в таблице tbl_example. ```Groovy endpoint.getConnection().firstRow("select count(*) from tbl_example").get('count') ``` -------------------------------- ### Getting Alarm States for a Specific Object Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to retrieve a list of alarm states for a specific object, such as a folder. ```Groovy folder = api.vsphere.mo('Folder', 'group-d1') endpoint.getAlarmState(folder) ``` -------------------------------- ### Getting Available Alarms for a Specific Object Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to retrieve a list of available alarms for a specific object, such as a folder. ```Groovy folder = api.vsphere.mo('Folder', 'group-d1') endpoint.getAlarm(folder) ``` -------------------------------- ### Getting Child Objects of a Specific Type within a Parent Object Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to retrieve a list of virtual machines within a specific folder. ```Groovy //Получение всех папок folders = endpoint.getObjectsByType('Folder') //Выбор нужной папки folder = folders.find{folder -> ... } vms = endpoint.getChilds(folder, 'VirtualMachine') ``` -------------------------------- ### Create deployment directories Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/instal_dap_Win.htm Creates dated directories for deployment updates and backups. ```powershell "update","backup" | %{New-Item -ItemType Directory -Path "d:\naumen\deploy\$(Get-Date -format "yyyy-MM-dd")\$_"} ``` -------------------------------- ### Querying Performance Metrics for a VM (All Metrics) Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to create a performance query for a virtual machine and retrieve the last 5 samples for all metrics. ```Groovy vm = api.vsphere.mo('VirtualMachine', 'vm-15') query = endpoint.createPerformanceQuery(vm) .maxSample(5) endpoint.queryPerf(query) ``` -------------------------------- ### asyncHttpClient(args) Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_HTTP.htm Создание асинхронного HTTP-клиента. Параметр: args — ассоциативный массив свойств HTTP-клиента (java.util.Map). Допустимые свойства: threadPool — пул потоков ThreadPoolExecutor; poolSize — размер пула потоков; uri — uri запроса по умолчанию; contentType — тип контента; timeout — таймаут запроса. Возвращаемое значение: объект groovyx.net.http.AsyncHTTPBuilder, необходимый для выполнения асинхронного HTTP-запроса. ```groovy def http = endpoint.asyncHttpClient(poolSize : 5); def result1 = http.request('http://site1.com', api.http.Methods.GET, api.http.ContentTypes.JSON) { response.success = {resp, html -> return resp.statusLine.statusCode }; response.failure = { resp -> return resp.statusLine.statusCode } } def result2 = http.request('http://site2.com', api.http.Methods.GET, api.http.ContentTypes.JSON) { response.success = {resp, html -> return resp.statusLine.statusCode }; response.failure = { resp -> return resp.statusLine.statusCode } } result1.get() == 200 && result2.get() == 200; ``` -------------------------------- ### Create directories for distribution Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/instal_dap_Win.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0+NDAP%7C_____4 Creates dated directories for storing the distribution files. ```PowerShell "update","backup" | %{New-Item -ItemType Directory -Path "d:\naumen\deploy\$(Get-Date -format "yyyy-MM-dd")\$_"} ``` -------------------------------- ### Install NDAP service Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/instal_dap_Win.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0+NDAP%7C_____4 Installs the NDAP service using NSSM and sets its display name. ```PowerShell d:\naumen\nssm\win64\nssm.exe install ndap d:\naumen\naudap\ndap-service.bat d:\naumen\nssm\win64\nssm.exe set ndap displayname Naumen Data Aggregation Platform ``` -------------------------------- ### Log4j2 Configuration Example Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/log4j2Properties.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%9A%D0%BE%D0%BD%D1%84%D0%B8%D0%B3%D1%83%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C_____2 This snippet demonstrates a basic log4j2 configuration, including root logger settings, file appender configuration with rolling policies, and specific logger level definitions. ```properties rootLogger.level=WARN rootLogger.appenderRef.ndap.ref=ndap appender.ndap.type=RollingFile appender.ndap.name=ndap appender.ndap.fileName=/opt/naumen/naudap/logs/ndap.log appender.ndap.filePattern=/opt/naumen/naudap/logs/ndap.log.%d{yyyy-MM-dd}.gz appender.ndap.layout.type=Log4jLayout appender.ndap.policies.type=Policies appender.ndap.policies.time.type=TimeBasedTriggeringPolicy appender.ndap.policies.time.interval=1 appender.ndap.policies.time.modulate=true appender.ndap.strategy.type=DefaultRolloverStrategy appender.ndap.strategy.action.type=Delete appender.ndap.strategy.action.basepath=/opt/naumen/naudap/logs appender.ndap.strategy.action.lastmodified.type=IfLastModified appender.ndap.strategy.action.lastmodified.age=P5D appender.ndap.strategy.action.filename.type=IfFileName appender.ndap.strategy.action.filename.glob=ndap.log.* logger.defNaumen.name=ru.naumen logger.defNaumen.level=INFO ``` -------------------------------- ### fitPredictiveModel Example 2 Source: https://www.naumen.ru/docs/sd/dap/Content/script/api_smpdap.htm Automatic selection of coefficients for an exponential smoothing model using the Nelder-Mead algorithm. This example includes specifying a date range for the data sampling period. ```javascript def model = utils.get('predictiveModel$2702'); def maxEval = 1000; def initialGuess = [ 0.5, 0.5, 0.5, 0.5 ] as double[]; def steps = [ 0.001, 0.001, 0.001, 0.001 ] as double[]; def from = new Date() - 1; def to = new Date(); api.ndap.fitPredictiveModel(model, maxEval, initialGuess, steps, from, to); ``` -------------------------------- ### fitPredictiveModel Example 1 Source: https://www.naumen.ru/docs/sd/dap/Content/script/api_smpdap.htm Automatic selection of coefficients for an exponential smoothing model using the Nelder-Mead algorithm. This example shows the basic usage without specifying a date range. ```javascript def model = utils.get('predictiveModel$2702'); def maxEval = 1000; def initialGuess = [ 0.5, 0.5, 0.5, 0.5 ] as double[]; def steps = [ 0.001, 0.001, 0.001, 0.001 ] as double[] api.ndap.fitPredictiveModel(model, maxEval, initialGuess, steps) ``` -------------------------------- ### Querying Performance Metrics for a VM (CPU Metrics) Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm Example of how to create a performance query for a virtual machine, filter for CPU metrics, and retrieve the last 5 samples. ```Groovy vm = api.vsphere.mo('VirtualMachine', 'vm-15') //Получаем метрики в группе 'cpu' metrics = endpoint.getMetrics(vm).findAll{ metric -> metric.info.groupInfo.key == 'cpu' } //Формируем запрос query = endpoint.createPerformanceQuery(vm) .maxSample(5) .metrics(metrics*.metric) // Получаем значения метрик endpoint.queryPerf(query) ``` -------------------------------- ### Копирование Influx CLI в PATH Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/migration.htm Команда для копирования исполняемого файла Influx CLI в каталог /usr/local/bin/. ```bash sudo cp influxdb2-client-2.4.0-linux-amd64/influx /usr/local/bin/ ``` -------------------------------- ### Event posting Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/DAP_rest.htm Example of posting an event to the event bus. ```json { "eventTime": 1606824479000, "eventSource": "VMware vCenter", "customAttrs": { "type": "error", "description": "Cannot login users\ivanov@192.168.100.11" } } ``` -------------------------------- ### isReachable() Example Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_ICMP.htm?TocPath=%D0%A1%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D1%8B%D0%B5+%D1%81%D1%86%D0%B5%D0%BD%D0%B0%D1%80%D0%B8%D0%B8.+DAP%7C%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B+API.+DAP%7C%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81%C2%A0%D0%BF%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%D0%BC%D0%B8.+DAP%7C_____3 Проверка доступности узла по IP-адресу. ```javascript endpoint.isReachable(); ``` -------------------------------- ### Create application directory structure Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/instal_dap_Linux.htm?TocPath=%D0%90%D0%B4%D0%BC%D0%B8%D0%BD%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5+DAP%7C%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0+NDAP%7C_____3 Creates the necessary directory structure for the NAUDAP application. ```bash mkdir -p /opt/naumen/naudap/{conf,logs,data} ``` -------------------------------- ### Остановка приложения (Linux - init.d) Source: https://www.naumen.ru/docs/sd/dap/Content/admin_dap/update_dap.htm Команда для остановки приложения Naumen DAP на Linux с использованием init.d. ```bash /etc/init.d/ndap stop ``` -------------------------------- ### Get PerformanceManager Reference Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_vSphere.htm?TocPath=%D0%A1%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D1%8B%D0%B5+%D1%81%D1%86%D0%B5%D0%BD%D0%B0%D1%80%D0%B8%D0%B8.+DAP%7C%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B+API.+DAP%7C%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81%C2%A0%D0%BF%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%D0%BC%D0%B8.+DAP%7C_____12 Retrieves a reference to the PerformanceManager object. ```Groovy endpoint.getPerformanceManager() ``` -------------------------------- ### Delete a registry value Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_WMI.htm?TocPath=%D0%A1%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D1%8B%D0%B5+%D1%81%D1%86%D0%B5%D0%BD%D0%B0%D1%80%D0%B8%D0%B8.+DAP%7C%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B+API.+DAP%7C%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81%C2%A0%D0%BF%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%D0%BC%D0%B8.+DAP%7C_____8 This example demonstrates how to delete a registry value. ```groovy endpoint.openRegistry({registry-> registry.openHKLM({ handle -> handle.open("Software\Microsoft\Windows\CurrentVersion\Uninstall\test", api.wmi.KEY_ALL_ACCESS, { rootNode-> rootNode.delete("testParam", false) }) }) }) ``` -------------------------------- ### getTime() Example Source: https://www.naumen.ru/docs/sd/dap/Content/DAP/api_DAP_connect_ICMP.htm?TocPath=%D0%A1%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D1%8B%D0%B5+%D1%81%D1%86%D0%B5%D0%BD%D0%B0%D1%80%D0%B8%D0%B8.+DAP%7C%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B+API.+DAP%7C%D0%A0%D0%B0%D0%B1%D0%BE%D1%82%D0%B0+%D1%81%C2%A0%D0%BF%D0%BE%D0%B4%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D1%8F%D0%BC%D0%B8.+DAP%7C_____3 Получение времени отклика от узла сети. ```javascript endpoint.getTime(); ```