Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev.icinga.com #13933] new function get_services(host_name) #4912

Closed
icinga-migration opened this issue Jan 10, 2017 · 8 comments · Fixed by #5534
Closed

[dev.icinga.com #13933] new function get_services(host_name) #4912

icinga-migration opened this issue Jan 10, 2017 · 8 comments · Fixed by #5534
Assignees
Labels
area/configuration DSL, parser, compiler, error handling enhancement New feature or request
Milestone

Comments

@icinga-migration
Copy link

This issue has been migrated from Redmine: https://dev.icinga.com/issues/13933

Created by KurdBahr on 2017-01-10 16:24:27 00:00

Assignee: (none)
Status: New
Target Version: Backlog
Last Update: 2017-01-11 17:09:28 00:00 (in Redmine)

Backport?: Not yet backported
Include in Changelog: 1

To get all services that are currently assigned to a host a new function get_services(host_name) would be useful.
This should be more efficient than iterating over all services returned by get_objects(Service) and checking the host_name.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2017-01-11 16:57:02 00:00

  • Target Version set to Backlog

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2017-01-11 17:09:28 00:00

If you want to start on a patch, look into lib/base/scriptutils.cpp and how "get_objects" is implemented. You'll then need to figure out whether the given host_name string translates into an actual Host object. Calling host->GetServices() and then adding that as a result set.

@icinga-migration icinga-migration added enhancement New feature or request libbase labels Jan 17, 2017
@icinga-migration icinga-migration added this to the Backlog milestone Jan 17, 2017
@marcofl
Copy link

marcofl commented Jul 5, 2017

1 for this. I'm currently using something like this:

...
    var hostname = macro("$hostname$");
    var filter_fn = function(svc) use(hostname) {
      var max_last_check = Math.min(86400, Math.max(300, svc.max_check_attempts * svc.check_interval))
      (svc.host_name == hostname && svc.last_check < (get_time() - max_last_check))
    }

    var res = [];
    for (s in get_objects(Service).filter(filter_fn)) {
       res.add(s.__name)
    };
...

which looks hacky and getting all our 50k services and then filtering down to the 30 services for the host does not make much sense. We think it's basically exposing Host::GetServices to the script language.

@dnsmichi
Copy link
Contributor

The main problem is that Host::GetServices() is located in libicinga, where libbase cannot link against. So there are specific script functions for libicinga required (correct me if I am wrong @gunnarbeutner :)).

@gunnarbeutner
Copy link
Contributor

I don't see a problem with adding a script function in lib/icinga/host.cpp or lib/icinga/objectutils.cpp.

@dnsmichi
Copy link
Contributor

dnsmichi commented Aug 23, 2017

Draft: edit: obsolete.

michi@mbmif ~/coding/icinga/exchange (master=) $ icinga2 console --connect 'https://root:icinga@localhost:5665/'
Icinga 2 (version: v2.7.0-73-gdfcd3ef11)
<1> => get_services(get_host(NodeName).name)
[ "5265-metrics", "disk", "disk /", "http", "icinga", "load", "pending", "ping4", "ping6", "procs", "ssh", "users" ]

@dnsmichi
Copy link
Contributor

<2> => get_services(NodeName).map(x => x.name)
[ "5265-metrics", "disk", "disk /", "http", "icinga", "load", "pending", "ping4", "ping6", "procs", "ssh", "users" ]
<3> => get_services(NodeName).map(x => x.last_check_result.check_source)
[ "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de" ]
<4> => get_services(get_host(NodeName)).map(x => x.last_check_result.check_source)
[ "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de", "mbmif.int.netways.de" ]


<6> => get_service(get_host(NodeName), "ssh").__name
"mbmif.int.netways.de!ssh"

@dnsmichi dnsmichi modified the milestones: 2.8.0, Backlog Aug 28, 2017
@dnsmichi dnsmichi self-assigned this Aug 28, 2017
@dnsmichi dnsmichi added area/configuration DSL, parser, compiler, error handling and removed wishlist labels Aug 28, 2017
dnsmichi pushed a commit that referenced this issue Aug 28, 2017
…t for get_service()

This includes some debug console examples too which involve advanced
map() and filter examples for better readability.

refs #4912
@marcofl
Copy link

marcofl commented Dec 4, 2017

works perfectly, thank you @dnsmichi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration DSL, parser, compiler, error handling enhancement New feature or request
Projects
None yet
4 participants