4 Ocak 2016 Pazartesi

Scriptize Your HSS Bulk Operations


The main idea is scriptize anything that takes more than script creation time. Creating a script will probably take less than half an hour for most of routine work. Once you prepare a script you will use it multiple times as needed, with small tweaks.

I have prepared the this script about one year ago. For a load test I need 1000 concurrent users on IMS. The hardest thing was creating those users on HSS.
It took about 15 minutes :)

1.       Export a template from from hss using your favorite ldap browser. (I prefer ldapadmin)
2.       Rename variable fields. (I use varuserid, varpass)
3.       Create a csv file for variable values.
4.       Run script
5.       Import output file to hss

You can find script and example data files in section Script1

After some time we need to change the service profile of the subscribers for another test. This was only a template file change ;)


Template file for changing the service profile:
dn: HSS-SubscriberServiceProfileId=varuserid@somedomain.com,HSS-SubscriberID=varuserid@somedomain.com,HSS-SubscriberContainerName=HSS-Subscribers,applicationName=HSS,nodeName=hssnodename
objectClass: HSS-SubscriberServiceProfile
changetype: modify
replace: HSS-ConfiguredServiceProfiles
HSS-ConfiguredServiceProfiles: centrex

And finally lets clean up our mess.

For deleting subcribers we have created following template can be used.

dn: HSS-SubscriberID=varuserid@somedomain.com,HSS-SubscriberContainerName=HSS-Subscribers,applicationName=HSS,nodeName=hssnodename
changetype: delete

From the beginning of the history, man is used to make tools in order to make his life simpler. Don’t hesitate to use your frontal lobe.

Script1 : generatesubs.pl
#!/usr/bin/perl -w

# Print the value of the command line arguments
$numArgs = $#ARGV + 1;


if ($numArgs<2) {
        print "Usage : \n";
        print "./generatesubs.pl output_file csv_file \n";
        print "Example : ./generatesubs.pl test.out values.csv \n";
                die;
} else {
        print "Output file is $ARGV[0]\n";
        print "CSV file is $ARGV[1]\n\n";
}

open OUTPUTFILE, ">", "$ARGV[0].ldif" or die $!;
open INPUTFILE2, "<", $ARGV[1] or die $!;

while (<INPUTFILE2>) {
$_ =~ s{^\Q$/\E}{};
my @number = split /,/, $_, 2;

  open INPUTFILE, "<", "template.ldif" or die $!;

  while (<INPUTFILE>) {

    $_ =~ s/varuserid/$number[0]/g;
    $_ =~ s/varpass/$number[1]/g;
    print OUTPUTFILE $_;
  }

  close INPUTFILE;

}
close OUTPUTFILE;
close INPUTFILE2;

Static Template File : template.ldif

dn: HSS-SubscriberID=varuserid@somedomain.com,HSS-SubscriberContainerName=HSS-Subscribers,applicationName=HSS,nodeName=hssnodename
objectClass: HSS-Subscriber
HSS-SubscriberID: varuserid@somedomain.com
HSS-SubscriberBarringInd: FALSE
HSS-ChargingProfId: DefaultChargingProfile
HSS-PrivacyIndicator: FALSE
HSS-IsPsiContainer: FALSE
HSS-ChargingId: varuserid

dn: HSS-PrivateUserID=varuserid@somedomain.com,HSS-SubscriberID=varuserid@somedomain.com,HSS-SubscriberContainerName=HSS-Subscribers,applicationName=HSS,nodeName=hssnodename
objectClass: HSS-User
HSS-PrivateUserID: varuserid@somedomain.com
HSS-RoamingAllowed: FALSE
HSS-AllowedAuthMechanism: Digest
HSS-UserPassword: varpass


dn: HSS-SubscriberServiceProfileId=varuserid@somedomain.com,HSS-SubscriberID=varuserid@somedomain.com,HSS-SubscriberContainerName=HSS-Subscribers,applicationName=HSS,nodeName=hssnodename
objectClass: HSS-SubscriberServiceProfile
HSS-SubscriberServiceProfileId: varuserid@somedomain.com
HSS-ConfiguredServiceProfiles: tispan
HSS-SubscribedMediaProfile:
HSS-PhoneContext: somedomain.com
HSS-MaxSessions: 3

dn: HSS-PublicIdValue=sip:varuserid@somedomain.com,HSS-SubscriberID=varuserid@somedomain.com,HSS-SubscriberContainerName=HSS-Subscribers,applicationName=HSS,nodeName=hssnodename
objectClass: HSS-PublicIdentificationData
HSS-PublicIdValue: sip:varuserid@somedomain.com
HSS-PrivateId: varuserid@somedomain.com
HSS-SubscriberServiceProfileId: varuserid@somedomain.com
HSS-XcapAllowed: FALSE
HSS-ImplicitRegSetId: 1
HSS-SessionBarringInd: FALSE
HSS-IsDefault: TRUE
HSS-MaxNumberOfContacts: 4

dn: HSS-PublicIdValue=tel:\+varuserid,HSS-SubscriberID=varuserid@somedomain.com,HSS-SubscriberContainerName=HSS-Subscribers,applicationName=HSS,nodeName=hssnodename
objectClass: HSS-PublicIdentificationData
HSS-PublicIdValue: tel:+varuserid
HSS-PrivateId: varuserid@somedomain.com
HSS-SubscriberServiceProfileId: varuserid@somedomain.com
HSS-ImplicitRegSetId: 1
HSS-SessionBarringInd: FALSE
HSS-IsDefault: TRUE
HSS-MaxNumberOfContacts: 4


Variable Values file : values.csv
908502091001,Pass123456
908502091002,Pass123456


reference for ldiff  options

https://www.digitalocean.com/community/tutorials/how-to-use-ldif-files-to-make-changes-to-an-openldap-system

2 yorum:

  1. "...scriptize anything that takes more than script creation time."
    So true! Reminded me of this classic: http://i.imgur.com/Q8kV8.png

    Good job by the way :)

    YanıtlaSil
    Yanıtlar
    1. "gets annoyed" point is very important. Mine is very low I guess :)

      Sil