Ad Widget

Collapse

Applying a template to 100's of nodes.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ptader
    Member
    • Sep 2007
    • 52

    #1

    Applying a template to 100's of nodes.

    Fresh 1.4.2 installation. I've imported several hundred similar nodes via an xml file I created and now want to apply the Linux template to all these nodes. I've attached the Linux template by going into the node details and linking with the it (Configuration -> Hosts -> select node1 -> "Link with Template") but this is a lot of work if it has to be repeated several hundred time. Easier way?

    Thanks,
    ptader
  • knarfling
    Member
    • Sep 2006
    • 47

    #2
    Auto Discovery

    My understanding is that is what Discovery is for. I have not used it, but my understanding is this.

    In configuration, you create a rule. Perhaps you want to scan a limited number of IP addresses. Perhaps you tell it to scan machines with an open port 80 (web). Maybe you check for email services or an active zabbix agent. You can put a number of criteria there so that it only finds the machines you want it to find.

    Once the rule is created, you create an action based on discovery. You can tell it to add a host, add a host to a group, and link it with a template. You can even link it to multiple templates.

    Although I have not had the need for this, I understand that you can link hundreds of servers in a very short time.

    Hope this helps!

    Comment

    • Alexei
      Founder, CEO
      Zabbix Certified Trainer
      Zabbix Certified SpecialistZabbix Certified Professional
      • Sep 2004
      • 5654

      #3
      Originally posted by ptader
      Fresh 1.4.2 installation. I've imported several hundred similar nodes via an xml file I created and now want to apply the Linux template to all these nodes. I've attached the Linux template by going into the node details and linking with the it (Configuration -> Hosts -> select node1 -> "Link with Template") but this is a lot of work if it has to be repeated several hundred time. Easier way?
      At the moment there is no easier way unfortunately. I am aware of this issue. Indeed maintenance of tens and hundreds of nodes is not simple without propagation of a template accross nodes. This will be addressed in future releases.
      Last edited by Alexei; 21-09-2007, 09:30.
      Alexei Vladishev
      Creator of Zabbix, Product manager
      New York | Tokyo | Riga
      My Twitter

      Comment

      • ptader
        Member
        • Sep 2007
        • 52

        #4
        Maybe a different way? It seems that after linking a template to a host group I get all the items in that template assigned and active to all the nodes in the group (excellent!). One odd behavior I did notice is that even when the link between the template and the host group is deleted individual templates checks from that template stay assigned to the node (ie. memory, hard drive, etc).

        Curious if you have any comments on this method.

        Thanks
        -ptader

        Comment

        • ptader
          Member
          • Sep 2007
          • 52

          #5
          I tried to add one host assign it to two templates into the hosts_templates table using mysql. The configuration/hosts web page reflected the Template membership change and I saw the addition to the table but it's "Availability" was "Unknown" and there are no items in the host list.

          I'm not a mysql expert by any means so I'd like to ask if there are some simple table changes I could script to modify these new hosts Template membership?

          Thanks,
          ptader

          Comment

          • lamont
            Member
            • Nov 2007
            • 89

            #6
            It looks like zabbix is using the hosts_templates table such that when you do an operation on the template it manually updates all the hosts associated with the template through that table, and not actually using the table to relate items to the hosts through the template. This means that if you've got an already created template with a bunch of stuff in it that adding a linkage in that table doesn't get you what you really want.

            What I'd like to know, however, is if you've just created a new template with nothing associated with it, is it safe to insert linkages into the hosts_templates table and then go from there, building out the template?

            Comment

            • lamont
              Member
              • Nov 2007
              • 89

              #7
              It looks like it would work to do something like (pseudo-code):

              function add_template_to_group (group, template)
              ..get all hosts in group
              ..loop over all hosts
              ....add linkage to hosts_templates table from host to template
              ....call sync_host_with_templates($hostid)
              ..end loop

              Comment

              • cristhiano
                Member
                • Nov 2007
                • 48

                #8
                I create a script to add hosts from cvs file to Zabbix. Put in frontend/php directory.
                I'm use "add_host" function of Zabbix code.

                ================================

                <?php

                include_once "include/hosts.inc.php";
                require_once "include/config.inc.php";

                $arq = "~/zabbix/hosts";

                $in = fopen($arq,"r") or exit("Err to open");

                while (($line = fgetcsv($in, 128, "\t")) !== false ){

                $groupname=$line[0];
                $result = DBselect("select * from groups where name=".zbx_dbstr($groupname));
                $r=DBfetch($result);

                if($r)
                $groupid=$r[groupid];
                else
                $groupid=add_host_group($groupname);

                $hostname=$line[0]."_".$line[1];

                $ip = $line[2]

                $hostid = add_host($hostname,10050,0,1,"",$ip,array(10025 => "MyTemplate"),null,array($groupid));

                }
                fclose($in);

                ?>

                =======================================

                You can use update_host (similar to add_host) to change your hosts.

                Comment

                • lamont
                  Member
                  • Nov 2007
                  • 89

                  #9
                  this seems to work:

                  <?php

                  include_once "include/hosts.inc.php";
                  require_once "include/config.inc.php";

                  $group = "ZABBIX Servers";

                  $template = "DELETEME";

                  $result = DBselect("select * from hosts where host=".zbx_dbstr($template));
                  $r=DBfetch($result);

                  if(!$r)
                  {
                  echo 'bad template';
                  exit;
                  }
                  else
                  {
                  echo $r[hostid];
                  }

                  echo '<p>';

                  $templateid = $r[hostid];

                  $result = DBselect("select * from groups where name=".zbx_dbstr($group));
                  $r=DBfetch($result);

                  if(!$r)
                  {
                  echo 'bad group';
                  exit;
                  }
                  else
                  {
                  echo $r[groupid];
                  }

                  $groupid = $r[groupid];

                  echo '<p>';

                  $results = DBselect("select * from hosts_groups where groupid=".$r[groupid]);
                  while($r = DBfetch($results))
                  {
                  $hostid = $r[hostid];
                  $hosttemplateid = get_dbid('hosts_templates', 'hosttemplateid');
                  $res = DBexecute('insert into hosts_templates values ('.$hosttemplateid.','.$hostid.','.$templateid.')' );
                  sync_host_with_templates($hostid);
                  echo $hostid;
                  echo '<p>';
                  }

                  echo 'done';

                  ?>

                  Comment

                  • lamont
                    Member
                    • Nov 2007
                    • 89

                    #10
                    The script above appears to have a really nasty side-effect. As far as i can see sync_host_with_templates() basically renumbered all the templated items for all templates associated with every host called by that script (deleting the old row in the database and inserting a new one?) without migrating the history data. So my history_uint table now has 15 million rows in it which do not join to the items table. All the information about which items the history datapoints map onto has been destroyed...

                    Comment

                    Working...