blob: 84fbcac802f7bb5de43d94ac535a7aff6aa31f3c [file] [log] [blame]
Wes Hardaker198aa3b2000-02-11 23:48:42 +00001#!/usr/bin/perl
Wes Hardakera932cb81999-04-12 21:32:43 +00002
3use DBI;
4$hostname = 'localhost'; # Host that serves the mSQL Database
5$dbname = 'snmp'; # mySQL Database name
6$doit = 1;
7
8sub usage {
Wes Hardaker4f3f21e2000-06-06 21:26:30 +00009 print "$0 [-H host] [-u user] [-p password] [-v] [-h] [-n] [-d] [-a] GROUP USER EMAILADDRESS\n";
Wes Hardakera932cb81999-04-12 21:32:43 +000010 exit 0;
11}
12
Wes Hardakera932cb81999-04-12 21:32:43 +000013while ($#ARGV > -1 && $ARGV[0] =~ /^-/) {
14 $_ = shift @ARGV;
15 usage if (/-h/);
16 $hostname = shift if (/-H/);
Wes Hardaker9b389c62001-06-01 14:40:05 +000017 $sqluser = shift if (/-u/);
Wes Hardakera932cb81999-04-12 21:32:43 +000018 $pass = shift if (/-p/);
19 $admin = 1 if (/-a/);
20 $verbose = 1 if (/-v/);
21 $delete = 1 if (/-d/);
22 $doit = 0 if (/-n/);
23}
24
Wes Hardaker4f3f21e2000-06-06 21:26:30 +000025($group, $user, $email) = @ARGV;
26
27die "group $group is a reserved group name, you can't use it. Sorry." if ($group eq "default");
Wes Hardakera932cb81999-04-12 21:32:43 +000028
29die "no group specified" if (!defined($group));
30
Wes Hardaker9b389c62001-06-01 14:40:05 +000031( $dbh = DBI->connect("DBI:mysql:database=$dbname;host=$hostname", $sqluser, $pass))
Wes Hardakera932cb81999-04-12 21:32:43 +000032 or die "\tConnect not ok: $DBI::errstr\n";
Wes Hardakera932cb81999-04-12 21:32:43 +000033
Wes Hardaker4f3f21e2000-06-06 21:26:30 +000034DO("insert into usergroups(user, groupname, isadmin) values('$user', '$group', " . (($admin) ? "'Y'" : "'N'") . ")");
35if (defined($email)) {
36 DO("insert into oncall(user, groupname, email, days, hours) values('$user', '$group', '$email', '*', '*')");
Wes Hardakera932cb81999-04-12 21:32:43 +000037}
Wes Hardaker4f3f21e2000-06-06 21:26:30 +000038
Wes Hardakera932cb81999-04-12 21:32:43 +000039$dbh->disconnect();
Wes Hardaker4f3f21e2000-06-06 21:26:30 +000040
41sub DO {
42 my $cmd = shift;
43 print $cmd,"\n" if ($verbose);
44 $dbh->do($cmd) if ($doit);
45}