1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
|
--
-- (C) 2020 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package.path
local pools = require("pools")
local check_utils = require("checks")
local endpoint_configs = require("endpoints")
local recipients_manager = require("recipients")
local page_utils = require('page_utils')
local telemetry_utils = require("telemetry_utils")
local toast_ui = require("toast_ui")
local stats_utils = require("stats_utils")
local delete_data_utils = require("delete_data_utils")
local prefs_factory_reset_utils = require("prefs_factory_reset_utils")
local configuration_utils = require "configuration_utils"
local info = ntop.getInfo()
local prefs = ntop.getPrefs()
local ToastLevel = toast_ui.ToastLevels
-- Constants
local ALARM_THRESHOLD_LOW = 60
local ALARM_THRESHOLD_HIGH = 90
local IS_ADMIN = isAdministrator()
local IS_SYSTEM_INTERFACE = page_utils.is_system_view()
local IS_PCAP_DUMP = interface.isPcapDumpInterface()
local IS_PACKET_INTERFACE = interface.isPacketInterface()
local UNEXPECTED_PLUGINS_ENABLED_CACHE_KEY = "ntopng.cache.checks.unexpected_plugins_enabled"
local predicates = {}
-- ###############################################################
local function create_DHCP_range_missing_notification(toast)
local title = i18n("about.configure_dhcp_range")
local description = i18n("about.dhcp_range_missing_warning", {
name = i18n("prefs.toggle_host_tskey_title"),
url = ntop.getHttpPrefix() .. "/lua/if_stats.lua?page=config",
dhcp_url = ntop.getHttpPrefix() .. "/lua/if_stats.lua?page=dhcp"
})
return toast_ui:new(toast.id, title, description, ToastLevel.WARNING, nil, toast.dismissable)
end
-- ###############################################################
local function create_DCHP_monitoring_toast(toast)
local title = i18n("about.dhcp_monitoring_title")
local description = i18n("about.host_identifier_warning", {
name = i18n("prefs.toggle_host_tskey_title"),
url = ntop.getHttpPrefix().."/lua/if_stats.lua?page=config"
})
local action = {
url = ntop.getHttpPrefix().."/lua/if_stats.lua?page=config",
title = i18n("configure")
}
return toast_ui:new(toast.id, title, description, ToastLevel.WARNING, action, toast.dismissable)
end
-- ###############################################################
local function create_DHCP_range_missing_toast(toast)
local title = i18n("about.dhcp_monitoring_title")
local description = i18n("about.dhcp_range_missing_warning", {
name = i18n("prefs.toggle_host_tskey_title"),
url = ntop.getHttpPrefix().."/lua/if_stats.lua?page=config",
dhcp_url = ntop.getHttpPrefix().."/lua/if_stats.lua?page=dhcp"
})
local action = {
url = ntop.getHttpPrefix().."/lua/if_stats.lua?page=dhcp",
title = i18n("configure")
}
return toast_ui:new(toast.id, title, description, ToastLevel.WARNING, action, toast.dismissable)
end
-- ###############################################################
local function create_geo_ip_toast_ui(toast)
local title = i18n("geolocation_unavailable_title")
local description = i18n("geolocation_unavailable", {
url = "https://github.com/ntop/ntopng/blob/dev/doc/README.geolocation.md",
target = "_blank",
icon = "fas fa-external-link-alt"
})
return toast_ui:new(toast.id, title, description, ToastLevel.WARNING, nil, toast.dismissable)
end
-- ###############################################################
local function create_contribute_toast_ui(toast)
local title = i18n("about.contribute_to_project")
local description = i18n("about.telemetry_data_opt_out_msg", {
tel_url = ntop.getHttpPrefix() .. "/lua/telemetry.lua",
ntop_org = "https://www.ntop.org/"
})
local action = {
url = ntop.getHttpPrefix() .. '/lua/admin/prefs.lua?tab=telemetry',
title = i18n("configure")
}
return toast_ui:new(toast.id, title, description, ToastLevel.INFO, action, toast.dismissable)
end
-- ###############################################################
local function create_forced_community_toast(toast)
local title = i18n("about.licence")
local description = i18n("about.forced_community_notification")
return toast_ui:new(toast.id, title, description, ToastLevel.WARNING, nil --[[ no action --]], toast.dismissable)
end
-- ###############################################################
local function create_tempdir_toast_ui(toast)
local title = i18n("warning")
local description = i18n("about.datadir_warning")
local action = {
url = "https://www.ntop.org/support/faq/migrate-the-data-directory-in-ntopng/",
title = i18n("details.details"),
}
return toast_ui:new(toast.id, title, description, ToastLevel.WARNING, action, toast.dismissable)
end
-- ###############################################################
local function create_update_ntopng_toast(toast, body)
local title = i18n("update")
return toast_ui:new(toast.id, title, body, ToastLevel.INFO, nil, toast.dismissable)
end
-- ###############################################################
local function create_too_many_flows_toast(toast, level)
local info = ntop.getInfo()
local title = i18n("too_many_flows")
local desc = i18n("about.you_have_too_many_flows",
{product = info["product"]})
local action = {
url = "#",
additional_classes = "toast-config-change-flows",
title = i18n("alert_messages.too_many_flows_title"),
js = "toast-config-change-flows.js",
dialog = {
id = 'toast-config-change-modal-flows',
action = 'toastConfigFlowChanges()',
title = i18n("too_many_flows"),
err_msg = i18n("alert_messages.too_many_flows_err"),
message = i18n("alert_messages.too_many_flows_details"),
custom_alert_class = 'alert alert-danger',
confirm = i18n('double_num_flows_hosts'),
confirm_button = 'btn-danger'
}
}
return toast_ui:new(toast.id, title, desc, level, action, toast.dismissable)
end
-- ###############################################################
local function create_too_many_hosts_toast(toast, level)
local info = ntop.getInfo()
local title = i18n("too_many_hosts")
local desc = i18n("about.you_have_too_many_hosts",
{product = info["product"]})
local action = {
url = "#",
additional_classes = "toast-config-change-hosts",
title = i18n("alert_messages.too_many_hosts_title"),
js = "toast-config-change-hosts.js",
dialog = {
id = 'toast-config-change-modal-hosts',
action = 'toastConfigHostChanges()',
title = i18n("too_many_hosts"),
err_msg = i18n("alert_messages.too_many_hosts_err"),
message = i18n("alert_messages.too_many_hosts_details"),
custom_alert_class = 'alert alert-danger',
confirm = i18n('double_num_flows_hosts'),
confirm_button = 'btn-danger'
}
}
return toast_ui:new(toast.id, title, desc, level, action, toast.dismissable)
end
-- ###############################################################
local function create_remote_probe_clock_drift_toast(toast, level, local_time, remote_time)
local title = i18n("remote_probe_clock_drift")
local desc = i18n("about.you_need_to_sync_remote_probe_time",
{url = ntop.getHttpPrefix() .. "/lua/if_stats.lua"})
local desc_times = i18n("about.remote_probe_times", {local_time = formatEpoch(local_time), remote_time = formatEpoch(remote_time)})
desc = string.format("%s<br>%s.", desc, desc_times)
return toast_ui:new(toast.id, title, desc, level, nil, toast.dismissable)
end
-- ##################################################################
local function create_flow_dump_toast_ui(toast)
local title = i18n("flow_dump_not_working_title")
local description = i18n("flow_dump_not_working", {
icon = "fas fa-external-link-alt"
})
return toast_ui:new(toast.id, title, description, ToastLevel.WARNING, nil, toast.dismissable)
end
-- ##################################################################
---
local function create_restart_required_toast(toast, description)
local title = i18n("restart.restart_required")
local action = nil
-- only the ntop packed can be restarted
if IS_ADMIN and ntop.isPackage() and not ntop.isWindows() then
action = {
title = i18n("restart.restart_now"),
additional_classes = "restart-service",
url = "#"
}
end
return toast_ui:new(toast.id, title, description, ToastLevel.DANGER, action, toast.dismissable)
end
-- ##################################################################
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.restart_required(toast, container)
if not IS_ADMIN or not ntop.isPackage() or ntop.isWindows() then return end
-- ifname is defined globally
local delete_active_interface_requested = delete_data_utils.delete_active_interface_data_requested(ifname)
if delete_active_interface_requested then
table.insert(container, create_restart_required_toast(toast, i18n("delete_data.restart_product_toast", {
product = ntop.getInfo()["product"]
})))
end
if prefs_factory_reset_utils.is_prefs_factory_reset_requested() then
table.insert(container, create_restart_required_toast(toast, i18n("manage_configurations.after_reset_request", {
product = ntop.getInfo()["product"]
})))
end
if configuration_utils.restart_required() then
table.insert(container, create_restart_required_toast(toast, i18n("manage_configurations.after_reset_request", {
product = ntop.getInfo()["product"]
})))
end
end
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.DHCP(toast, container)
if not IS_ADMIN then return end
-- In System Interface we can't collect the required data
if (IS_SYSTEM_INTERFACE) then return false end
local ifs = interface.getStats()
if (not(ifs.has_seen_dhcp_addresses and IS_ADMIN and (not IS_PCAP_DUMP) and IS_PACKET_INTERFACE)) then
return
end
local lbd_serialize_by_mac = (_POST["lbd_hosts_as_macs"] == "1") or
(ntop.getPref(string.format("ntopng.prefs.ifid_%u.serialize_local_broadcast_hosts_as_macs",ifs.id)) == "1")
if (not lbd_serialize_by_mac) and
(ntop.getPref(string.format("ntopng.prefs.ifid_%u.disable_host_identifier_message", ifs.id)) ~= "1") then
table.insertIfNotPresent(container, create_DCHP_monitoring_toast(toast), function(n) return n.id == toast.id end)
elseif isEmptyString(_POST["dhcp_ranges"]) then
local dhcp_utils = require("dhcp_utils")
local ranges = dhcp_utils.listRanges(ifs.id)
if (table.empty(ranges)) then
table.insertIfNotPresent(container, create_DHCP_range_missing_toast(toast), function(n) return n.id == toast.id end)
end
end
end
--- Create an instance for the geoip alert toast
--- if the user doesn't have geoIP installed
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.geo_ip(toast, container)
if IS_ADMIN and not ntop.hasGeoIP() then
table.insert(container, create_geo_ip_toast_ui(toast))
end
end
--- Create an instance for the temp working directory alert
--- if ntopng is running inside /var/tmp
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.temp_working_dir(toast, container)
if not IS_ADMIN or ntop.isWindows() then return end
if (dirs.workingdir == "/var/tmp/ntopng") then
table.insert(container, create_tempdir_toast_ui(toast))
end
end
--- Create an instance for contribute alert toast
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.contribute(toast, container)
if not IS_ADMIN then return end
if (not info.oem) and (not telemetry_utils.dismiss_notice()) then
table.insert(container, create_contribute_toast_ui(toast))
end
end
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.update_ntopng(toast, container)
if not IS_ADMIN or not ntop.isPackage() or ntop.isWindows() then return end
-- check if ntopng is oem and the user is an Administrator
local is_not_oem_and_administrator = IS_ADMIN and not info.oem
local message = check_latest_major_release()
if is_not_oem_and_administrator and not isEmptyString(message) then
table.insert(container, create_update_ntopng_toast(toast, message))
end
end
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.too_many_hosts(toast, container)
if not IS_ADMIN or not ntop.isPackage() or ntop.isWindows() then return end
-- In System Interface we can't get the hosts number from `interface.getNumHosts()`
if (IS_SYSTEM_INTERFACE) then return end
local level = nil
local hosts = interface.getNumHosts()
local hosts_pctg = math.floor(1 + ((hosts * 100) / prefs.max_num_hosts))
if (hosts_pctg >= ALARM_THRESHOLD_LOW and hosts_pctg <= ALARM_THRESHOLD_HIGH) then
level = ToastLevel.WARNING
elseif (hosts_pctg > ALARM_THRESHOLD_HIGH) then
level = ToastLevel.DANGER
end
if (level ~= nil) then
table.insert(container, create_too_many_hosts_toast(toast, level))
end
end
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.too_many_flows(toast, container)
if not IS_ADMIN or not ntop.isPackage() or ntop.isWindows() then return end
-- In System Interface we can't get the flows number from `interface.getNumFlows()`
if (IS_SYSTEM_INTERFACE) then return end
local level = nil
local flows = interface.getNumFlows()
local flows_pctg = math.floor(1 + ((flows * 100) / prefs.max_num_flows))
if (flows_pctg >= ALARM_THRESHOLD_LOW and flows_pctg <= ALARM_THRESHOLD_HIGH) then
level = ToastLevel.WARNING
elseif (flows_pctg > ALARM_THRESHOLD_HIGH) then
level = ToastLevel.DANGER
end
if (level ~= nil) then
table.insert(container, create_too_many_flows_toast(toast, level))
end
end
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.remote_probe_clock_drift(toast, container)
if not IS_ADMIN then return end
-- In System Interface we can't collect the stats from `interface.getStats()`
if (IS_SYSTEM_INTERFACE) then return end
local ifstats = interface.getStats()
if ifstats["probe.remote_time"] ~= nil and
ifstats["probe.local_time"] ~= nil then
local tdiff = math.abs(ifstats["probe.local_time"] - ifstats["probe.remote_time"])
local level = nil
if (tdiff >= 10 and tdiff <= 30) then
level = ToastLevel.WARNING
elseif (tdiff > 30) then
level = ToastLevel.DANGER
end
if (level ~= nil) then
table.insert(container, create_remote_probe_clock_drift_toast(toast, level, ifstats["probe.local_time"], ifstats["probe.remote_time"]))
end
end
end
--- Create an instance for the nIndex alert toast
--- if nIndex is not able to start/run/dump
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.flow_dump(toast, container)
if not IS_ADMIN or not ntop.isPackage() or ntop.isWindows() then return end
-- In System Interface we can't collect the stats from `interface.getStats()`
if (IS_SYSTEM_INTERFACE) then return end
local ifstats = interface.getStats()
if IS_ADMIN and prefs.is_dump_flows_enabled and
prefs.is_dump_flows_runtime_enabled and not ifstats.isFlowDumpDisabled and
not ifstats.isFlowDumpRunning and not ifstats.isViewed then
table.insert(container, create_flow_dump_toast_ui(toast))
end
end
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.about_page(toast, container)
if not IS_ADMIN then return end
if (_POST["ntopng_license"] ~= nil) then
ntop.setCache('ntopng.license', trimSpace(_POST["ntopng_license"]))
ntop.checkLicense()
ntop.setCache('ntopng.cache.force_reload_plugins', '1') -- housekeeping.lua will reload plugins
info = ntop.getInfo()
if (info["version.enterprise_l_edition"] and info["pro.license"] ~= "") then
table.insert(container,
toast_ui:new(toast.id, i18n("info"), i18n("about.create_license_l"), ToastLevel.INFO, {
url = "https://www.ntop.org/support/faq/what-is-included-in-ntopng-enterprise-l/",
title = i18n("details.details")
})
)
elseif (not info["version.enterprise_l_edition"] and info["pro.license"] ~= "") then
table.insert(container, toast_ui:new(toast.id, i18n("info"), i18n("about.create_license"), ToastLevel.INFO))
end
end
end
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.hosts_geomap(toast, container)
if not IS_ADMIN then return end
local hosts_stats = interface.getHostsInfo()
local num = hosts_stats["numHosts"]
if (num > 0) then
table.insert(container,
toast_ui:new(toast.id, i18n("warning"), i18n("geo_map.warning_accuracy"), ToastLevel.WARNING, nil, toast.dismissable)
)
end
end
--- This is a simple placeholder for new toasts
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.empty(toast, container)
-- do nothing!
end
--- Generate two toasts if the SNMP ratio is not available for probes
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.exporters_SNMP_ratio_column(toast, container)
if not IS_ADMIN or not ntop.isPro() then return end
local snmp_utils = require "snmp_utils"
local snmp_cached_dev = require "snmp_cached_dev"
local flow_device_ip = _GET["ip"]
if (isEmptyString(flow_device_ip)) then return end
local cached_device = snmp_cached_dev:create(flow_device_ip)
local is_ratio_available = snmp_utils.is_snmp_ratio_available(cached_device)
if (is_ratio_available) then return end
local title = i18n("flow_devices.enable_flow_ratio")
local body
local action = nil
-- Did the user add the device to the SNMP overview page?
local device_exists = not(cached_device == nil)
-- Are SNMP Timeseries enabled?
local snmp_dev_creation = ntop.getPref("ntopng.prefs.snmp_devices_rrd_creation") == "1"
-- Are Flow Probes Timseries enabled?
local flow_dev_creation = ntop.getPref("ntopng.prefs.flow_device_port_rrd_creation") == "1"
if not device_exists then
-- Build the message to show
local message_snmp = i18n("flow_devices.flow_ratio_snmp_instructions", {
href = ntop.getHttpPrefix() .. "/lua/pro/enterprise/snmpdevices_stats.lua"
})
body = message_snmp
elseif not flow_dev_creation or not snmp_dev_creation then
-- Build the message to show
local message_timeseries = i18n("flow_devices.flow_ratio_timeseries_instructions")
body = message_timeseries
action = {
url = '#',
title = i18n("enable_them"),
}
end
if body then
table.insert(container, toast_ui:new(toast.id, title, body, ToastLevel.INFO, action, toast.dismissable))
end
end
-- ###############################################
--- Create an instance for forced community toast
--- @param toast table The toast is the logic model defined in defined_toasts
--- @param container table Is the table where to put the new toast ui
function predicates.forced_community(toast, container)
if(ntop.getInfo()["pro.forced_community"] and ntop.exists("/etc/ntopng.license")) then
table.insert(container, create_forced_community_toast(toast))
end
end
-- ###############################################
--- Did the user create an non builtin endpoint?
local function user_has_created_endpoint()
return ntop.getCache(endpoint_configs.FIRST_ENDPOINT_CREATED_CACHE_KEY) == "1"
end
--- Did the user create a recipient?
local function user_has_created_recipient()
return ntop.getCache(recipients_manager.FIRST_RECIPIENT_CREATED_CACHE_KEY) == "1"
end
--- Did the user bind a recipient to a pool?
local function user_has_bound_recipient()
return ntop.getCache(pools.FIRST_RECIPIENT_BOUND_CACHE_KEY) == "1"
end
--- Generate a toast to adive the user about toast endpoints
function predicates.create_endpoint(toast, container)
if (not IS_ADMIN) then return end
if (user_has_created_endpoint()) then return end
if IS_PCAP_DUMP then return end
local title = i18n("endpoint_notifications.hints.create_endpoint.title")
local body = i18n("endpoint_notifications.hints.create_endpoint.body", {
link = "https://www.ntop.org/guides/ntopng/plugins/alert_endpoints.html"
})
local action = {
title = i18n("endpoint_notifications.hints.create_endpoint.action"),
url = ntop.getHttpPrefix() .. "/lua/admin/endpoint_notifications_list.lua"
}
local hint = toast_ui:new(toast.id, title, body, ToastLevel.INFO, action, toast.dismissable)
table.insert(container, hint)
end
-- Generate a second toast to inform the user to create a recipient for the new endpoint
function predicates.create_recipients_for_endpoint(toast, container)
if (not IS_ADMIN) then return end
if IS_PCAP_DUMP then return end
-- Did the user created a new endpoint? If not then return
if (not user_has_created_endpoint()) then return end
-- Did the user created the new recipient? If yes then return
if (user_has_created_recipient()) then return end
local title = i18n("endpoint_notifications.hints.create_recipients.title")
local body = i18n("endpoint_notifications.hints.create_recipients.body", {
link = "https://www.ntop.org/guides/ntopng/plugins/alert_endpoints.html"
})
local action = {
url = ntop.getHttpPrefix() .. "/lua/admin/recipients_list.lua",
title = i18n("create")
}
local hint = toast_ui:new(toast.id, title, body, ToastLevel.INFO, action, toast.dismissable)
table.insert(container, hint)
end
--- Generate a third notificiation to inform the user to bind the new recipients to a pool
function predicates.bind_recipient_to_pools(toast, container)
if (not IS_ADMIN) then return end
if (not user_has_created_endpoint()) then return end
if (not user_has_created_recipient()) then return end
if (user_has_bound_recipient()) then return end
if IS_PCAP_DUMP then return end
local title = i18n("endpoint_notifications.hints.bind_pools.title")
local body = i18n("endpoint_notifications.hints.bind_pools.body")
local action = {
url = ntop.getHttpPrefix() .. "/lua/admin/manage_pools.lua",
title = i18n("bind")
}
local hint = toast_ui:new(toast.id, title, body, ToastLevel.INFO, action, toast.dismissable)
table.insert(container, hint)
end
--- Check if unexpected plugins are disabled and notifiy the user
--- about their existance
function predicates.unexpected_plugins(toast, container)
if (not IS_ADMIN) then return end
if not isEmptyString(ntop.getCache(UNEXPECTED_PLUGINS_ENABLED_CACHE_KEY)) then return end
local url = ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua?subdir=flow&search_script=unexpected#disabled"
-- TODO: missing documentation links
local title = i18n("checks.hint.title")
local body = i18n("checks.hint.body", {
link_DHCP = "https://ntop.org",
link_SMTP = "https://ntop.org",
link_DNS = "https://ntop.org",
link_NTP = "https://ntop.org",
product = info["product"]
})
local action = { url = url, title = i18n("configure")}
local hint = toast_ui:new(toast.id, title, body, ToastLevel.INFO, action, toast.dismissable)
table.insert(container, hint)
end
-- ###############################################
function predicates.export_drops(toast, container)
if (IS_SYSTEM_INTERFACE) then return end
local is_dump_flows_enabled = prefs.is_dump_flows_enabled
if is_dump_flows_enabled then
local ifstats = interface.getStats()
local total_flows = ifstats.stats_since_reset.flow_export_count
local flow_export_drops = ifstats.stats_since_reset.flow_export_drops
local severity = ToastLevels[stats_utils.get_severity_by_export_drops(flow_export_drops, total_flows)]
-- for the info severity don't show anything
if severity == ToastLevels.INFO then return end
local body = i18n("about.too_many_exports", {
product = "<b>" .. info.product .. "</b>"
})
local hint = toast_ui:new(toast.id, i18n("too_many_exports"), body, severity, nil, toast.dismissable)
table.insert(container, hint)
end
end
-- ###############################################
--- Create an instance for the obsolete nindex support
function predicates.obsolete_nindex(toast, container)
if not IS_ADMIN then return end
if prefs.is_nindex_enabled then
local title = i18n("obsolete_nindex")
local body = i18n("obsolete_nindex_message")
local hint = toast_ui:new(toast.id, title, body, ToastLevel.WARNING, nil, toast.dismissable)
table.insert(container, hint)
end
end
-- ###############################################
--- Create an instance for the obsolete MySQL support
function predicates.obsolete_mysql(toast, container)
if not IS_ADMIN then return end
if prefs.is_dump_flows_to_mysql_enabled and not prefs.is_dump_flows_to_clickhouse_enabled then
local title = i18n("obsolete_mysql")
local body = i18n("obsolete_mysql_message")
local hint = toast_ui:new(toast.id, title, body, ToastLevel.WARNING, nil, toast.dismissable)
table.insert(container, hint)
end
end
-- ###############################################
return predicates
|