Ad Widget

Collapse

Mass user creation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeremyh
    Junior Member
    • Apr 2013
    • 2

    #1

    Mass user creation

    I'm working on adding close to 100 users to my Zabbix 2.0.5 instance and am hoping there is a way to create these users in a more automated way.

    We have successfully configured Zabbix to auth via LDAP to a Windows AD system. Unless I'm missing something, this authentication requires that users still be created locally.

    I've looked at the API, user.create in the documentation but I'm at a loss of how to use it.

    Anyone have any insights, how-to's or advice?

    Thanks in advance,
    Jeremy H.
  • BDiE8VNy
    Senior Member
    • Apr 2010
    • 680

    #2
    Do you have already taken a look at?:

    Comment

    • dirckcopeland
      Member
      • Oct 2013
      • 50

      #3
      Create Users in Mass

      Here are some examples to use that are more specific to adding users using the API. Here is a useful perl example that looks simple but took a while even after looking at the above links.

      Code:
      #!/usr/bin/perl
      
      use 5.010;
      use strict;
      use warnings;
      use JSON::RPC::Client;
      use Data::Dumper;
      
      # Authenticate yourself
      my $client = new JSON::RPC::Client;
      my $url = 'http://your-zabbix-server-here.com/zabbix/api_jsonrpc.php';
      
      my $authID;
      my $response;
      
      # Get list of all hosts using authID
      
      my $json = {
      jsonrpc=> '2.0',
      method => 'user.create',
      params => 
      {
      alias => 'john.doe',
      name => 'John',
      surname => 'Doe',
      passwd => 'changeme',
      usrgrps =>
      {
      usrgrpid => 25
      }
      },
      id => 1,
      auth => "abc23283babcbabdbfbeb3238f01e92b"
      };
      
      $response = $client->call($url, $json);
      print Dumper($response);
      printf "%s\n",$response;
      So the next question I had is how do you find the usrgrpid number associated with the group you want add this users to. Heres the code to list out the User Groups and associated ID's:

      Code:
      #!/usr/bin/perl
      
      use 5.010;
      use strict;
      use warnings;
      use JSON::RPC::Client;
      use Data::Dumper;
      
      # Authenticate yourself
      my $client = new JSON::RPC::Client;
      my $url = 'http://your-zabbix-server.com/zabbix/api_jsonrpc.php';
      
      my $authID;
      my $response;
      
      my $json = {
      jsonrpc=> '2.0',
      method => 'usergroup.get',
      params =>
      {
      output => 'extend'
      },
      id => 2,
      auth => "abc23283babcbabdbfbeb3238f01e92b",
      };
      $response = $client->call($url, $json);
      
      # Check if response was successful
      die "host.get failed\n" unless $response->content->{result};
      
      print "List of Groups\n-----------------------------\n";
      foreach my $usergroup (@{$response->content->{result}}) {
      print "Group ID: ".$usergroup->{usrgrpid}." Name: ".$usergroup->{name}."\n";
      }
      Last edited by dirckcopeland; 05-01-2015, 23:45.

      Comment

      • BDiE8VNy
        Senior Member
        • Apr 2010
        • 680

        #4
        Originally posted by dirckcopeland
        Not sure why people can't post something useful instead of just pointing to the documentation. [...]
        [/CODE]
        Possibly to help people how to find a way themselves

        Comment

        Working...