Skip to content

Instantly share code, notes, and snippets.

@tomas-edwardsson
Created February 19, 2014 16:04
Show Gist options
  • Save tomas-edwardsson/9095108 to your computer and use it in GitHub Desktop.
Save tomas-edwardsson/9095108 to your computer and use it in GitHub Desktop.
Add all hosts to hostgroup
import pynag.Model
for host in pynag.Model.Host.objects.all:
# Object has host_name
if host.host_name:
if 'my-hostgroup' not in host.hostgroups:
host.add_to_hostgroup('my-hostgroup')
host.save()
@palli
Copy link

palli commented Feb 19, 2014

import pynag.Model

for host in pynag.Model.Host.objects.filter(host_name__exists=True, register="1"):
    host.add_host_hostgroup('my-hostgroup')
    host.save()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment