├── .idea
├── .name
├── encodings.xml
├── vcs.xml
├── modules.xml
├── iControl-GettingStarted.iml
└── misc.xml
├── lib
├── axis.jar
├── log4j.jar
├── mail.jar
├── saaj.jar
├── jaxrpc.jar
├── wsdl4j.jar
├── activation.jar
├── axis-ant.jar
├── iControl.jar
├── log4j-1.2.8.jar
├── wsdl4j-1.5.1.jar
├── commons-logging.jar
├── commons-discovery.jar
├── commons-discovery-0.2.jar
└── commons-logging-1.0.4.jar
├── makejava.sh
├── ignoreSSL.ps1
├── SOAP-CreatePoolInPartition.py
├── REST-CreatePoolInPartition.py
├── SOAP-DataGroup.py
├── REST-CreatePoolInPartition.js
├── SOAP-CreatePoolInPartition.pl
├── REST-CreatePoolInPartition.ps1
├── SOAP-CreatePoolInPartition.java
├── SOAPCreatePoolInPartition.java
├── REST-system.py
├── SOAP-CreatePoolInPartition.ps1
├── REST-DataGroup.py
├── REST-CreatePoolInPartition.pl
├── REST-Stats.py
├── REST-DataGroup.js
├── SOAP-DataGroup.ps1
├── SOAP-DataGroup.pl
├── REST-Stats.js
├── REST-system.ps1
├── SOAPDataGroup.java
├── REST-DataGroup.ps1
├── REST-DataGroup.pl
└── REST-Stats.ps1
/.idea/.name:
--------------------------------------------------------------------------------
1 | iControl-GettingStarted
--------------------------------------------------------------------------------
/lib/axis.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/axis.jar
--------------------------------------------------------------------------------
/lib/log4j.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/log4j.jar
--------------------------------------------------------------------------------
/lib/mail.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/mail.jar
--------------------------------------------------------------------------------
/lib/saaj.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/saaj.jar
--------------------------------------------------------------------------------
/lib/jaxrpc.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/jaxrpc.jar
--------------------------------------------------------------------------------
/lib/wsdl4j.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/wsdl4j.jar
--------------------------------------------------------------------------------
/lib/activation.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/activation.jar
--------------------------------------------------------------------------------
/lib/axis-ant.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/axis-ant.jar
--------------------------------------------------------------------------------
/lib/iControl.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/iControl.jar
--------------------------------------------------------------------------------
/lib/log4j-1.2.8.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/log4j-1.2.8.jar
--------------------------------------------------------------------------------
/lib/wsdl4j-1.5.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/wsdl4j-1.5.1.jar
--------------------------------------------------------------------------------
/lib/commons-logging.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/commons-logging.jar
--------------------------------------------------------------------------------
/lib/commons-discovery.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/commons-discovery.jar
--------------------------------------------------------------------------------
/lib/commons-discovery-0.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/commons-discovery-0.2.jar
--------------------------------------------------------------------------------
/lib/commons-logging-1.0.4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f5devcentral/iControl-GettingStarted/HEAD/lib/commons-logging-1.0.4.jar
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/iControl-GettingStarted.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/makejava.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | javac -d ./class -classpath .:./lib/axis.jar:./lib/commons-discovery.jar:./lib/commons-logging.jar:./lib/jaxrpc.jar:./lib/saaj.jar:./lib/wsdl4j.jar:./lib/activation.jar:./lib/mail.jar:./lib/iControl.jar SOAPCreatePoolInPartition.java
4 |
5 | javac -d ./class -classpath .:./lib/axis.jar:./lib/commons-discovery.jar:./lib/commons-logging.jar:./lib/jaxrpc.jar:./lib/saaj.jar:./lib/wsdl4j.jar:./lib/activation.jar:./lib/mail.jar:./lib/iControl.jar SOAPDataGroup.java
6 |
--------------------------------------------------------------------------------
/ignoreSSL.ps1:
--------------------------------------------------------------------------------
1 | ## Source: http://www.datacore.com/RESTSupport-Webhelp/using_windows_powershell_as_a_rest_client.htm
2 | function Ignore-SelfSignedCerts
3 | {
4 | try
5 | {
6 |
7 | Write-Host "Adding TrustAllCertsPolicy type." -ForegroundColor White
8 | Add-Type -TypeDefinition @"
9 | using System.Net;
10 | using System.Security.Cryptography.X509Certificates;
11 | public class TrustAllCertsPolicy : ICertificatePolicy
12 | {
13 | public bool CheckValidationResult(
14 | ServicePoint srvPoint, X509Certificate certificate,
15 | WebRequest request, int certificateProblem)
16 | {
17 | return true;
18 | }
19 | }
20 | "@
21 |
22 | Write-Host "TrustAllCertsPolicy type added." -ForegroundColor White
23 | }
24 | catch
25 | {
26 | Write-Host $_ -ForegroundColor "Yellow"
27 | }
28 |
29 | [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
30 | }
31 |
32 | Ignore-SelfSignedCerts
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Buildout
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SOAP-CreatePoolInPartition.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | '''
3 | # The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
4 | # Software Development Kit for iControl"; you may not use this file except in
5 | # compliance with the License. The License is included in the iControl
6 | # Software Development Kit.
7 | #
8 | # Software distributed under the License is distributed on an "AS IS"
9 | # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10 | # the License for the specific language governing rights and limitations
11 | # under the License.
12 | #
13 | # The Original Code is iControl Code and related documentation
14 | # distributed by F5.
15 | #
16 | # The Initial Developer of the Original Code is F5 Networks,
17 | # Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
18 | # Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc.
19 | #
20 | # Alternatively, the contents of this file may be used under the terms
21 | # of the GNU General Public License (the "GPL"), in which case the
22 | # provisions of GPL are applicable instead of those above. If you wish
23 | # to allow use of your version of this file only under the terms of the
24 | # GPL and not to allow others to use your version of this file under the
25 | # License, indicate your decision by deleting the provisions above and
26 | # replace them with the notice and other provisions required by the GPL.
27 | # If you do not delete the provisions above, a recipient may use your
28 | # version of this file under either the License or the GPL.
29 | '''
30 |
31 |
32 | def get_pool_list(bigip):
33 | try:
34 | poollist = bigip.LocalLB.Pool.get_list()
35 | print "POOL LIST"
36 | print " ---------"
37 | for pool in poollist:
38 | print " %s" % pool
39 |
40 | except Exception, e:
41 | print e
42 |
43 |
44 | def create_pool(bigip, pool):
45 | try:
46 | bigip.LocalLB.Pool.create_v2([pool], ['LB_METHOD_ROUND_ROBIN'], [[]])
47 | except Exception, e:
48 | print e
49 |
50 |
51 | if __name__ == "__main__":
52 | import bigsuds, argparse, getpass, ssl
53 | ssl._create_default_https_context = ssl._create_unverified_context
54 |
55 | parser = argparse.ArgumentParser(description='Create Pool')
56 |
57 | parser.add_argument("host", help='BIG-IP IP or Hostname' )
58 | parser.add_argument("username", help='BIG-IP Username')
59 | parser.add_argument("-p", "--poolname", help='Name of pool you wish to create')
60 | parser.add_argument("-f", "--folder", help='Partition/Folder you want the pool to reside in')
61 | args = vars(parser.parse_args())
62 |
63 | hostname = args['host']
64 | username = args['username']
65 | poolname = None if args['poolname'] is None else args['poolname']
66 | partition = None if args['folder'] is None else args['folder']
67 |
68 | print "%s, enter your password: " % args['username'],
69 | password = getpass.getpass()
70 |
71 | b = bigsuds.BIGIP(hostname, username, password)
72 |
73 | if poolname is None:
74 | get_pool_list(b)
75 | else:
76 | if partition is None:
77 | poolname = '/Common/%s' % poolname
78 | else:
79 | poolname = '/%s/%s' % (partition, poolname)
80 | create_pool(b, poolname)
--------------------------------------------------------------------------------
/REST-CreatePoolInPartition.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | '''
3 | # The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
4 | # Software Development Kit for iControl"; you may not use this file except in
5 | # compliance with the License. The License is included in the iControl
6 | # Software Development Kit.
7 | #
8 | # Software distributed under the License is distributed on an "AS IS"
9 | # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10 | # the License for the specific language governing rights and limitations
11 | # under the License.
12 | #
13 | # The Original Code is iControl Code and related documentation
14 | # distributed by F5.
15 | #
16 | # The Initial Developer of the Original Code is F5 Networks,
17 | # Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
18 | # Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc.
19 | #
20 | # Alternatively, the contents of this file may be used under the terms
21 | # of the GNU General Public License (the "GPL"), in which case the
22 | # provisions of GPL are applicable instead of those above. If you wish
23 | # to allow use of your version of this file only under the terms of the
24 | # GPL and not to allow others to use your version of this file under the
25 | # License, indicate your decision by deleting the provisions above and
26 | # replace them with the notice and other provisions required by the GPL.
27 | # If you do not delete the provisions above, a recipient may use your
28 | # version of this file under either the License or the GPL.
29 | '''
30 |
31 |
32 |
33 | def get_pool_list(bigip, url):
34 | try:
35 | pools = bigip.get("%s/ltm/pool" % url).json()
36 | print "POOL LIST"
37 | print " ---------"
38 | for pool in pools['items']:
39 | print " /%s/%s" % (pool['partition'], pool['name'])
40 | except Exception, e:
41 | print e
42 |
43 |
44 | def create_pool(bigip, url, pool, part=None):
45 | try:
46 | payload = {}
47 | payload['name'] = pool
48 | if part is not None:
49 | payload['partition'] = part
50 |
51 | pool_config = bigip.post("%s/ltm/pool" % url, json.dumps(payload)).json()
52 | print pool_config
53 | except Exception, e:
54 | print e
55 |
56 |
57 | if __name__ == "__main__":
58 | import requests, json, argparse, getpass
59 | from requests.packages.urllib3.exceptions import InsecureRequestWarning
60 | requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
61 |
62 | parser = argparse.ArgumentParser(description='Create Pool')
63 |
64 | parser.add_argument("host", help='BIG-IP IP or Hostname' )
65 | parser.add_argument("username", help='BIG-IP Username')
66 | parser.add_argument("-p", "--poolname", help='Name of pool you wish to create')
67 | parser.add_argument("-f", "--folder", help='Partition you want the pool to reside in')
68 | args = vars(parser.parse_args())
69 |
70 | hostname = args['host']
71 | username = args['username']
72 | poolname = None if args['poolname'] is None else args['poolname']
73 | partition = None if args['folder'] is None else args['folder']
74 |
75 | print "%s, enter your password: " % args['username'],
76 | password = getpass.getpass()
77 |
78 | b_url_base = 'https://%s/mgmt/tm' % hostname
79 | b = requests.session()
80 | b.auth = (username, password)
81 | b.verify = False
82 | b.headers.update({'Content-Type':'application/json'})
83 |
84 | if poolname is None:
85 | get_pool_list(b, b_url_base)
86 | else:
87 | if partition is None:
88 | create_pool(b, b_url_base, poolname)
89 | else:
90 | create_pool(b, b_url_base, poolname, partition)
--------------------------------------------------------------------------------
/SOAP-DataGroup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | '''
3 | # The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
4 | # Software Development Kit for iControl"; you may not use this file except in
5 | # compliance with the License. The License is included in the iControl
6 | # Software Development Kit.
7 | #
8 | # Software distributed under the License is distributed on an "AS IS"
9 | # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10 | # the License for the specific language governing rights and limitations
11 | # under the License.
12 | #
13 | # The Original Code is iControl Code and related documentation
14 | # distributed by F5.
15 | #
16 | # The Initial Developer of the Original Code is F5 Networks,
17 | # Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
18 | # Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc.
19 | #
20 | # Alternatively, the contents of this file may be used under the terms
21 | # of the GNU General Public License (the "GPL"), in which case the
22 | # provisions of GPL are applicable instead of those above. If you wish
23 | # to allow use of your version of this file only under the terms of the
24 | # GPL and not to allow others to use your version of this file under the
25 | # License, indicate your decision by deleting the provisions above and
26 | # replace them with the notice and other provisions required by the GPL.
27 | # If you do not delete the provisions above, a recipient may use your
28 | # version of this file under either the License or the GPL.
29 | '''
30 |
31 | def get_dg_list(bigip):
32 | try:
33 | dg_str_list = bigip.LocalLB.Class.get_string_class_list()
34 | dg_str_names = bigip.LocalLB.Class.get_string_class(dg_str_list)
35 |
36 |
37 | for dg in dg_str_names:
38 | print dg
39 | print ' Data Group: %s' % dg['name']
40 | for x in dg['members']:
41 | print ' %s' % x
42 |
43 | except Exception, e:
44 | print e
45 |
46 |
47 | def extend_dg(bigip, dgname, keys, values):
48 | try:
49 | bigip.LocalLB.Class.add_string_class_member([{'name': dgname, 'members': keys}])
50 | bigip.LocalLB.Class.set_string_class_member_data_value([{'name': dgname, 'members': keys}], [[values]])
51 | except Exception, e:
52 | print e
53 |
54 |
55 | def contract_dg(bigip, dgname, keys):
56 | try:
57 | bigip.LocalLB.Class.delete_string_class_member([{'name': dgname, 'members': keys}])
58 | except Exception, e:
59 | print e
60 |
61 |
62 | def create_dg(bigip, dgname, keys, values):
63 | try:
64 | bigip.LocalLB.Class.create_string_class([{'name': dgname, 'members': keys}])
65 | bigip.LocalLB.Class.set_string_class_member_data_value([{'name': dgname, 'members': keys}], [[values]])
66 | except Exception, e:
67 | print e
68 |
69 |
70 | if __name__ == "__main__":
71 | import bigsuds, argparse, getpass, ssl
72 | ssl._create_default_https_context = ssl._create_unverified_context
73 |
74 | parser = argparse.ArgumentParser(description='Create Data-Group')
75 |
76 | parser.add_argument("host", help='BIG-IP IP or Hostname' )
77 | parser.add_argument("username", help='BIG-IP Username')
78 | parser.add_argument("-d", "--datagroup", help='Name of the data-group you want to create')
79 | args = vars(parser.parse_args())
80 |
81 | hostname = args['host']
82 | username = args['username']
83 | datagroupname = None if args['datagroup'] is None else args['datagroup']
84 |
85 | print "%s, enter your password: " % args['username'],
86 | password = getpass.getpass()
87 |
88 | b = bigsuds.BIGIP(hostname, username, password)
89 |
90 | dg_members_init = ['a', 'b', 'c']
91 | dg_values_init = [1, 2, 3]
92 |
93 | dg_members_add = ['d', 'e']
94 | dg_values_add = [4, 5]
95 |
96 | dg_members_del = ['b']
97 |
98 |
99 | if datagroupname is None:
100 | get_dg_list(b)
101 | else:
102 | create_dg(b, datagroupname, dg_members_init, dg_values_init)
103 | extend_dg(b, datagroupname, dg_members_add, dg_values_add)
104 | contract_dg(b, datagroupname, dg_members_del)
105 |
--------------------------------------------------------------------------------
/REST-CreatePoolInPartition.js:
--------------------------------------------------------------------------------
1 | #!/usr/local/bin/node
2 |
3 | //=========================================================
4 | //
5 | //=========================================================
6 | var net = require('net');
7 | var stdio = require('stdio');
8 | var https = require('https');
9 | var net = require('net');
10 | var url = require('url');
11 | var request = require('request');
12 | var util = require('util');
13 |
14 | var ops = stdio.getopt({
15 | 'bigip' : { key: 'b', args: 1, description: 'BIG-IP address', default: 'bigip.joesmacbook.com'},
16 | 'user' : { key: 'u', args: 1, description: 'Username', default: 'admin'},
17 | 'pass' : { key: 'p', args: 1, description: 'Password', default: 'admin'},
18 | 'pool' : { key: 'o', args: 1, description: 'Pool'},
19 | 'partition' : { key: 'a', args: 1, description: 'Partition'},
20 | 'debug' : { key: 'd', description: 'Print Debug Messages'}
21 | });
22 |
23 | var BIGIP = ops.bigip;
24 | var USER = ops.user;
25 | var PASS = ops.pass;
26 | var POOL = ops.pool;
27 | var PARTITION = ops.partition;
28 | var DEBUG = ops.debug;
29 |
30 | var args = ops.args;
31 |
32 |
33 | //--------------------------------------------------------
34 | function buildUrl(resource) {
35 | //--------------------------------------------------------
36 | return "https://" + BIGIP + resource;
37 | }
38 |
39 | //--------------------------------------------------------
40 | function getAuthToken(callback) {
41 | //--------------------------------------------------------
42 | var resource = "/mgmt/shared/authn/login";
43 | var user = USER;
44 | var pass = PASS;
45 | var body = "{'username':'" + user + "','password':'" + pass + "','loginProviderName':'tmos'}";
46 |
47 | httpRequest("POST", resource, body, user, pass, null, function(json) {
48 | var obj = JSON.parse(json);
49 | var token = obj["token"]["token"];
50 | callback(token);
51 | });
52 | }
53 |
54 | //--------------------------------------------------------
55 | function httpRequest(verb, resource, body, user, pass, token, callback) {
56 | //--------------------------------------------------------
57 |
58 | if ( DEBUG ) { console.log("\n: " + resource + "\n"); }
59 |
60 | var http_opts = {
61 | host: BIGIP,
62 | method: verb,
63 | port: 443,
64 | rejectUnauthorized: 0,
65 | path: resource
66 | };
67 |
68 | var http_headers = {
69 | 'Content-Type': 'application/json'
70 | };
71 |
72 | // Authentication Method
73 | if ( user && pass ) { http_opts["auth"] = user + ":" + pass; }
74 | else if ( token ) { http_headers["X-F5-Auth-Token"] = token; }
75 |
76 | // BODY?
77 | if ( body ) { http_headers["Content-Length"] = body.length; }
78 |
79 | http_opts["headers"] = http_headers;
80 |
81 | var content = "";
82 | var req = https.request(http_opts, function(res) {
83 | res.setEncoding("utf8");
84 | res.on('data', function(chunk) {
85 | content += chunk;
86 | }),
87 | res.on('end', function() {
88 | callback(content);
89 | })
90 | });
91 |
92 | req.on('error', function(e) {
93 | console.log("ERROR: " + JSON.stringify(e) + "\n");
94 | });
95 |
96 | if ( body ) {
97 | req.write(body + "\n");
98 | }
99 | req.end();
100 | }
101 |
102 |
103 | //--------------------------------------------------------
104 | function handleVERB(verb, resource, body, callback) {
105 | //--------------------------------------------------------
106 | getAuthToken( function(token) {
107 | httpRequest(verb, resource, body, null, null, token, function(json) {
108 | callback(json);
109 | });
110 | });
111 | }
112 |
113 |
114 | function handleGetPoolList(callback) {
115 | var uri = "/mgmt/tm/ltm/pool";
116 | handleVERB("GET", uri, null, function(json) {
117 | callback(json);
118 | });
119 | }
120 |
121 | function handleCreatePool(pool, partition, callback) {
122 | var uri = "/mgmt/tm/ltm/pool";
123 | var body = '{"name":"' + pool + '", "partition":"' + partition + '"}';
124 |
125 | console.log("BODY: " + body);
126 | handleVERB("POST", uri, body, function(json) {
127 | callback(json);
128 | });
129 | }
130 |
131 | //========================================================
132 | //
133 | //========================================================
134 |
135 | if ( (null == POOL) || (PARTITION == null) ) {
136 | handleGetPoolList(function(json) {
137 | var obj = JSON.parse(json);
138 | var items = obj.items;
139 | var len = items.length;
140 | console.log("POOL NAMES");
141 | console.log("==========");
142 | for(var i=0; i qw(method debug);
32 | use SOAP::Lite;
33 | use MIME::Base64;
34 |
35 | $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
36 |
37 | #----------------------------------------------------------------------------
38 | # Validate Arguments
39 | #----------------------------------------------------------------------------
40 | my $sHost = $ARGV[0];
41 | my $sUID = $ARGV[1];
42 | my $sPWD = $ARGV[2];
43 | my $sPool = $ARGV[3];
44 | my $sPartition = $ARGV[4];
45 |
46 | if ( $Partition eq "") { $Partition = "/Dev"; }
47 |
48 | if ( ($sHost eq "") or ($sUID eq "") or ($sPWD eq "") )
49 | {
50 | die ("Usage: LocalLBPoolCreate.pl host uid pwd [pool_name partition]\n");
51 | }
52 |
53 | #----------------------------------------------------------------------------
54 | # Transport Information
55 | #----------------------------------------------------------------------------
56 | sub SOAP::Transport::HTTP::Client::get_basic_credentials
57 | {
58 | return "$sUID" => "$sPWD";
59 | }
60 |
61 | $Pool = SOAP::Lite
62 | -> uri('urn:iControl:LocalLB/Pool')
63 | -> proxy("https://$sHost/iControl/iControlPortal.cgi");
64 | eval { $Pool->transport->http_request->header
65 | (
66 | 'Authorization' =>
67 | 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
68 | ); };
69 |
70 | if ( $sPool eq "" )
71 | {
72 | &getPoolList();
73 | #&getAllPoolInfo();
74 | }
75 | else
76 | {
77 | &createPool($sPartition, $sPool);
78 | #&getPoolInfo($sPool);
79 | }
80 |
81 | #----------------------------------------------------------------------------
82 | # checkResponse
83 | #----------------------------------------------------------------------------
84 | sub checkResponse()
85 | {
86 | my ($soapResponse) = (@_);
87 | if ( $soapResponse->fault )
88 | {
89 | print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
90 | exit();
91 | }
92 | }
93 |
94 | #----------------------------------------------------------------------------
95 | # getPoolList
96 | #----------------------------------------------------------------------------
97 | sub getPoolList()
98 | {
99 | $soapResponse = $Pool->get_list();
100 | &checkResponse($soapResponse);
101 | my @pool_list = @{$soapResponse->result};
102 | print "POOL LIST\n";
103 | print "---------\n";
104 | foreach $pool (@pool_list) {
105 | print " ${pool}\n";
106 | }
107 | }
108 |
109 | #----------------------------------------------------------------------------
110 | # createPool()
111 | #----------------------------------------------------------------------------
112 | sub createPool()
113 | {
114 | my ($partition, $pool) = @_;
115 |
116 | print "CREATING POOL $pool\n";
117 |
118 | my @pool_names = [$pool];
119 | my @lb_methods = ["LB_METHOD_ROUND_ROBIN"];
120 | $member =
121 | {
122 | address => "10.10.10.10",
123 | port => 80
124 | };
125 |
126 | # memberA is the 1st dimension of the array, we need one for each pool
127 | push @memberA, $member;
128 | # memberAofA is the 2nd dimension. push pool members for each pool here.
129 | push @memberAofA, [@memberA];
130 |
131 | $soapResponse = $Pool->create(
132 | SOAP::Data->name( pool_names => ["/$partition/$pool"]),
133 | SOAP::Data->name( lb_methods => ["LB_METHOD_ROUND_ROBIN"]),
134 | SOAP::Data->name(members => [@memberAofA])
135 | );
136 | &checkResponse($soapResponse);
137 |
138 | print "POOL ${pool} created in partition ${partition}...\n";
139 | }
140 |
141 |
--------------------------------------------------------------------------------
/REST-CreatePoolInPartition.ps1:
--------------------------------------------------------------------------------
1 | #----------------------------------------------------------------------------
2 | # The contents of this file are subject to the "END USER LICENSE AGREEMENT
3 | # FOR F5 Software Development Kit for iControl"; you may not use this file
4 | # except in compliance with the License. The License is included in the
5 | # iControl Software Development Kit.
6 | #
7 | # Software distributed under the License is distributed on an "AS IS"
8 | # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 | # the License for the specific language governing rights and limitations
10 | # under the License.
11 | #
12 | # The Original Code is iControl Code and related documentation
13 | # distributed by F5.
14 | #
15 | # The Initial Developer of the Original Code is F5 Networks,
16 | # Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2009
17 | # F5 Networks, Inc. All Rights Reserved. iControl (TM) is a registered
18 | # trademark of F5 Networks, Inc.
19 | #
20 | # Alternatively, the contents of this file may be used under the terms
21 | # of the GNU General Public License (the "GPL"), in which case the
22 | # provisions of GPL are applicable instead of those above. If you wish
23 | # to allow use of your version of this file only under the terms of the
24 | # GPL and not to allow others to use your version of this file under the
25 | # License, indicate your decision by deleting the provisions above and
26 | # replace them with the notice and other provisions required by the GPL.
27 | # If you do not delete the provisions above, a recipient may use your
28 | # version of this file under either the License or the GPL.
29 | #----------------------------------------------------------------------------
30 | param(
31 | [string]$Bigip = "",
32 | [string]$User = "",
33 | [string]$Pass = "",
34 | [string]$Pool = "",
35 | [string]$Partition = ""
36 | );
37 |
38 | #----------------------------------------------------------------------------
39 | function Get-PoolList()
40 | #----------------------------------------------------------------------------
41 | {
42 | $uri = "/mgmt/tm/ltm/pool";
43 | $link = "https://$Bigip$uri";
44 | $headers = @{};
45 | $headers.Add("ServerHost", $Bigip);
46 |
47 | $secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
48 | $mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
49 |
50 | $obj = Invoke-RestMethod -Method GET -Headers $headers -Uri $link -Credential $mycreds
51 | $items = $obj.items;
52 | Write-Host "POOL NAMES";
53 | Write-Host "----------";
54 | for($i=0; $i -lt $items.length; $i++) {
55 | $name = $items[$i].fullPath;
56 | Write-Host " $name";
57 | }
58 | }
59 |
60 | #----------------------------------------------------------------------------
61 | function Create-Pool()
62 | #
63 | # Description:
64 | # This function creates a new pool if the given pool name doesn't
65 | # already exist.
66 | #
67 | # Parameters:
68 | # Name - The Name of the pool you wish to create.
69 | # Partition - The name of the partition to place the pool in.
70 | #----------------------------------------------------------------------------
71 | {
72 | param(
73 | [string]$Name,
74 | [string]$Partition
75 | );
76 |
77 | $uri = "/mgmt/tm/ltm/pool";
78 | $link = "https://$Bigip$uri";
79 | $headers = @{};
80 | $headers.Add("ServerHost", $Bigip);
81 | $headers.Add("Content-Type", "application/json");
82 | $obj = @{
83 | name=$Name
84 | partition=$Partition
85 | };
86 | $body = $obj | ConvertTo-Json
87 |
88 | $secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
89 | $mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
90 |
91 | $obj = Invoke-RestMethod -Method POST -Uri $link -Headers $headers -Credential $mycreds -Body $body;
92 |
93 | Write-Host "Pool ${Name} created in partition ${Partition}"
94 | }
95 |
96 | #----------------------------------------------------------------------------
97 | function Show-Usage()
98 | #
99 | # Description:
100 | # This function will print the script usage information.
101 | #
102 | #----------------------------------------------------------------------------
103 | {
104 | Write-Host @"
105 | Usage: CreatePoolInPartition.ps1 Arguments
106 | Argument - Description
107 | ---------- -----------
108 | Bigip - The ip/hostname of your BIG-IP.
109 | User - The Managmenet username for your BIG-IP.
110 | Pass - The Management password for your BIG-IP.
111 | Pool - The Name of the pool to create.
112 | Partition - The Partition to place the pool in.
113 | "@;
114 | }
115 |
116 | #============================================================================
117 | # Main application logic
118 | #============================================================================
119 | if ( ($Bigip.Length -eq 0) -or ($User.Length -eq 0) -or ($Pass.Length -eq 0) ) {
120 | Show-Usage;
121 | } else {
122 | if ( ($Pool.Length -eq 0) -or ($Partition.Length -eq 0) ) {
123 | Get-PoolList;
124 | } else {
125 | Create-Pool -Name $Pool -Partition $Partition;
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/SOAP-CreatePoolInPartition.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
3 | * Software Development Kit for iControl"; you may not use this file except in
4 | * compliance with the License. The License is included in the iControl
5 | * Software Development Kit.
6 | *
7 | * Software distributed under the License is distributed on an "AS IS"
8 | * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 | * the License for the specific language governing rights and limitations
10 | * under the License.
11 | *
12 | * The Original Code is iControl Code and related documentation
13 | * distributed by F5.
14 | *
15 | * The Initial Developer of the Original Code is F5 Networks,
16 | * Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2002 F5
17 | * Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Netw
18 | *
19 | * Alternatively, the contents of this file may be used under the terms
20 | * of the GNU General Public License (the "GPL"), in which case the
21 | * provisions of GPL are applicable instead of those above. If you wish
22 | * to allow use of your version of this file only under the terms of the
23 | * GPL and not to allow others to use your version of this file under the
24 | * License, indicate your decision by deleting the provisions above and
25 | * replace them with the notice and other provisions required by the GPL.
26 | * If you do not delete the provisions above, a recipient may use your
27 | * version of this file under either the License or the GPL.
28 | */
29 |
30 | import java.text.*;
31 | import java.util.*;
32 | import java.io.*;
33 |
34 | public class SOAPCreatePoolInPartition extends Object
35 | {
36 | //--------------------------------------------------------------------------
37 | // Member Variables
38 | //--------------------------------------------------------------------------
39 | public iControl.Interfaces m_interfaces = new iControl.Interfaces();
40 |
41 | //--------------------------------------------------------------------------
42 | // Constructor
43 | //--------------------------------------------------------------------------
44 | public SOAPCreatePoolInPartition()
45 | {
46 | }
47 |
48 | //--------------------------------------------------------------------------
49 | // parseArgs
50 | // [0] bigip
51 | // [1] user
52 | // [2] pass
53 | // [3] poolname
54 | // [4] partition
55 | //--------------------------------------------------------------------------
56 | public boolean parseArgs(String[] args) throws Exception
57 | {
58 | boolean bSuccess = false;
59 | int port = 443;
60 | String bigip = null;
61 | String user = null;
62 | String pass = null;
63 | String poolname = null;
64 | String partition = null;
65 |
66 | int len = args.length;
67 | System.out.println("LEN: " + len);
68 |
69 | if ( args.length < 3 )
70 | {
71 | usage();
72 | }
73 | else
74 | {
75 | bigip = args[0];
76 | user = args[1];
77 | pass = args[2];
78 |
79 | if ( args.length > 3 )
80 | {
81 | poolname = args[3];
82 | }
83 | if ( args.length > 4 )
84 | {
85 | partition = args[4];
86 | }
87 |
88 | // build parameters
89 | m_interfaces.initialize(bigip, port, user, pass);
90 |
91 | if ( (null == poolname) || (null == partition) ) {
92 | displayAllPools();
93 | } else {
94 | createPool(poolname, partition);
95 | }
96 | bSuccess = true;
97 | }
98 |
99 | return bSuccess;
100 | }
101 |
102 | //--------------------------------------------------------------------------
103 | //
104 | //--------------------------------------------------------------------------
105 | public void usage()
106 | {
107 | System.out.println("Usage: SOAPCreatePoolInPartition hostname username password [pool partition]");
108 | }
109 |
110 | public void displayAllPools() throws Exception
111 | {
112 | String [] pool_list = m_interfaces.getLocalLBPool().get_list();
113 | System.out.println("Pools\n");
114 | System.out.println("-----------\n");
115 | for(int i=0; i 3 )
80 | {
81 | poolname = args[3];
82 | }
83 | if ( args.length > 4 )
84 | {
85 | partition = args[4];
86 | }
87 |
88 | // build parameters
89 | m_interfaces.initialize(bigip, port, user, pass);
90 |
91 | if ( (null == poolname) || (null == partition) ) {
92 | displayAllPools();
93 | } else {
94 | createPool(poolname, partition);
95 | }
96 | bSuccess = true;
97 | }
98 |
99 | return bSuccess;
100 | }
101 |
102 | //--------------------------------------------------------------------------
103 | //
104 | //--------------------------------------------------------------------------
105 | public void usage()
106 | {
107 | System.out.println("Usage: SOAPCreatePoolInPartition hostname username password [pool partition]");
108 | }
109 |
110 | public void displayAllPools() throws Exception
111 | {
112 | String [] pool_list = m_interfaces.getLocalLBPool().get_list();
113 | System.out.println("Pools\n");
114 | System.out.println("-----------\n");
115 | for(int i=0; inew->allow_nonref;
17 |
18 | my $BIGIP = "";
19 | my $USER = "";
20 | my $PASS = "";
21 | my $POOL = "";
22 | my $PARTITION = "";
23 | my $AUTH_TOKEN = "";
24 | my $RESOURCE = "";
25 | my $DEBUG = 0;
26 |
27 | GetOptions(
28 | 'bigip=s' => \$BIGIP,
29 | "user=s" => \$USER,
30 | "pass=s" => \$PASS,
31 | "user=s" => \$USER,
32 | "pool=s" => \$POOL,
33 | "partition=s" => \$PARTITION,
34 | "debug" => \$DEBUG
35 | );
36 |
37 | sub usage() {
38 | print "Usage: REST-CreatePoolInPartition.pl [options] \n";
39 | print " options\n";
40 | print " ----------------\n";
41 | print " --bigip bigip_addr\n";
42 | print " --user bigip_username\n";
43 | print " --pass bigip_password\n";
44 | print " --pool pool_name\n";
45 | print " --partition partition_name\n";
46 | print "\n";
47 | exit();
48 | };
49 |
50 | #---------------------------------------------------
51 | sub getAuthToken() {
52 | #---------------------------------------------------
53 | $url = "https://${BIGIP}/mgmt/shared/authn/login";
54 | $user = $USER;
55 | $pass = $PASS;
56 |
57 | $body = "{'username':'$user','password':'$pass','loginProviderName':'tmos'}";
58 |
59 | $json = postHttpRequest($url, $body, 1);
60 |
61 | $obj = decode_json($json);
62 | $AUTH_TOKEN = $obj->{token}->{token};
63 |
64 | if ( $DEBUG ) {
65 | print "TOKEN: $AUTH_TOKEN\n";
66 | }
67 |
68 | return $AUTH_TOKEN;
69 | }
70 |
71 | #---------------------------------------------------
72 | sub getHttpRequest() {
73 | #---------------------------------------------------
74 | my ($url) = (@_);
75 |
76 | if ( $DEBUG ) {
77 | print "REQUESTING URL : ${url}\n";
78 | }
79 |
80 | $content = "";
81 | if ( $url ) {
82 | my $ua = LWP::UserAgent->new;
83 | my $req = HTTP::Request->new(GET => $url);
84 | #$req->authorization_basic($USER, $PASS);
85 | my $auth_token = &getAuthToken();
86 | if ( "" ne $auth_token ) {
87 | $req->header("X-F5-Auth-Token" => $auth_token);
88 | }
89 |
90 | $resp = $ua->request($req);
91 | if ( $DEBUG ) {
92 | print Dumper($resp);
93 | }
94 |
95 | if ( $resp->is_success ) {
96 | $content = $resp->content;
97 | #print "CONTENT: ${content}\n";
98 | } else {
99 | $code = $resp->code;
100 | $msg = $resp->message;
101 | $content = $resp->content;
102 | die "HTTP ERROR ${code} : \"${msg}\" : \"${content}\"\n";
103 | }
104 | }
105 | return $content;
106 | }
107 |
108 | #---------------------------------------------------
109 | sub postHttpRequest() {
110 | #---------------------------------------------------
111 | my ($url, $body, $basicauth) = (@_);
112 |
113 | if ( $DEBUG ) {
114 | print "REQUESTING URL (POST) : ${url}\n";
115 | }
116 |
117 | $content = "";
118 | if ( $url ) {
119 | my $ua = LWP::UserAgent->new;
120 | my $req = HTTP::Request->new(POST => $url);
121 |
122 | if ( $basicauth == 1 ) {
123 | $req->authorization_basic($USER, $PASS);
124 | } else {
125 | my $auth_token = &getAuthToken();
126 | if ( "" ne $auth_token ) {
127 | $req->header("X-F5-Auth-Token" => $auth_token);
128 | }
129 | }
130 |
131 | $req->header("Content-Type" => "application/json");
132 | $req->content($body);
133 |
134 | $resp = $ua->request($req);
135 | if ( $DEBUG ) {
136 | print Dumper($resp);
137 | }
138 |
139 | if ( $resp->is_success ) {
140 | $content = $resp->content;
141 | #print "CONTENT: ${content}\n";
142 | } else {
143 | $code = $resp->code;
144 | $msg = $resp->message;
145 | $content = $resp->content;
146 | die "HTTP ERROR ${code} : \"${msg}\" : \"${content}\"\n";
147 | }
148 | }
149 | return $content;
150 | }
151 |
152 | #---------------------------------------------------
153 | sub buildURL() {
154 | #---------------------------------------------------
155 | my ($resource) = @_;
156 |
157 | $url = "https://${BIGIP}/$resource";
158 |
159 | return $url;
160 | }
161 |
162 | #---------------------------------------------------
163 | sub handleGET() {
164 | #---------------------------------------------------
165 | my ($resource) = @_;
166 |
167 | $url = &buildURL($resource);
168 |
169 | $resp = &getHttpRequest($url);
170 |
171 | return $resp;
172 | }
173 |
174 | #---------------------------------------------------
175 | sub handlePOST() {
176 | #---------------------------------------------------
177 | my ($resource, $body) = @_;
178 |
179 | if ( $body eq "" ) { &usage(); }
180 |
181 | $url = &buildURL($resource);
182 |
183 | $resp = &postHttpRequest($url, $body);
184 |
185 | return $resp;
186 | }
187 |
188 | #---------------------------------------------------
189 | sub getPoolList() {
190 | #---------------------------------------------------
191 | $resp_json = &handleGET("/mgmt/tm/ltm/pool");
192 | $resp = decode_json($resp_json);
193 | @items = @{$resp->{"items"}};
194 |
195 | print "POOL NAMES\n";
196 | print "----------\n";
197 | foreach $item (@items) {
198 | $fullPath = $item->{"fullPath"};
199 | print " $fullPath\n";
200 | print Dumper($item);
201 | }
202 | }
203 |
204 | #---------------------------------------------------
205 | sub createPool() {
206 | #---------------------------------------------------
207 | my ($pool, $partition) = @_;
208 |
209 | my $poolObj;
210 | $poolObj->{"name"} = $pool;
211 | $poolObj->{"partition"} = $partition;
212 |
213 | my $json = encode_json($poolObj);
214 |
215 | print "JSON: $json\n";
216 | exit();
217 |
218 | $resp = &handlePOST("/mgmt/tm/ltm/pool", $json);
219 |
220 | print Dumper($resp);
221 | }
222 |
223 |
224 |
225 | #===================================================
226 |
227 | #===================================================
228 |
229 |
230 | if ( ($BIGIP eq "") || ($USER eq "") || ($PASS eq "") ) {
231 | &usage();
232 | } else {
233 | if ( ($POOL eq "") || ($PARTITION eq "") ) {
234 | &getPoolList($POOL, $PARTITION);
235 | } else {
236 | &createPool($POOL, $PARTITION);
237 | }
238 | }
239 |
--------------------------------------------------------------------------------
/REST-Stats.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | '''
3 | # The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5
4 | # Software Development Kit for iControl"; you may not use this file except in
5 | # compliance with the License. The License is included in the iControl
6 | # Software Development Kit.
7 | #
8 | # Software distributed under the License is distributed on an "AS IS"
9 | # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10 | # the License for the specific language governing rights and limitations
11 | # under the License.
12 | #
13 | # The Original Code is iControl Code and related documentation
14 | # distributed by F5.
15 | #
16 | # The Initial Developer of the Original Code is F5 Networks,
17 | # Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks,
18 | # Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc.
19 | #
20 | # Alternatively, the contents of this file may be used under the terms
21 | # of the GNU General Public License (the "GPL"), in which case the
22 | # provisions of GPL are applicable instead of those above. If you wish
23 | # to allow use of your version of this file only under the terms of the
24 | # GPL and not to allow others to use your version of this file under the
25 | # License, indicate your decision by deleting the provisions above and
26 | # replace them with the notice and other provisions required by the GPL.
27 | # If you do not delete the provisions above, a recipient may use your
28 | # version of this file under either the License or the GPL.
29 | '''
30 |
31 |
32 | def get_pool_list(bigip, url):
33 | try:
34 | pools = bigip.get("%s/ltm/pool" % url).json()
35 | print "POOL LIST"
36 | print " ---------"
37 | for pool in pools['items']:
38 | print " /%s/%s" % (pool['partition'], pool['name'])
39 | except Exception, e:
40 | print e
41 |
42 |
43 | def get_pool_stats(bigip, url, pool):
44 | try:
45 | pool_stats = bigip.get("%s/ltm/pool/%s/stats" % (url, pool)).json()
46 | selflink = "https://localhost/mgmt/tm/ltm/pool/%s/~Common~%s/stats" % (pool, pool)
47 | nested_stats = pool_stats['entries'][selflink]['nestedStats']['entries']
48 | print ''
49 | print ' --------------------------------------'
50 | print ' NAME : %s' % nested_stats['tmName']['description']
51 | print ' --------------------------------------'
52 | print ' AVAILABILITY STATE : %s' % nested_stats['status.availabilityState']['description']
53 | print ' ENABLED STATE : %s' % nested_stats['status.enabledState']['description']
54 | print ' REASON : %s' % nested_stats['status.statusReason']['description']
55 | print ' SERVER BITS IN : %s' % nested_stats['serverside.bitsIn']['value']
56 | print ' SERVER BITS OUT : %s' % nested_stats['serverside.bitsOut']['value']
57 | print ' SERVER PACKETS IN : %s' % nested_stats['serverside.pktsIn']['value']
58 | print ' SERVER PACKETS OUT : %s' % nested_stats['serverside.pktsOut']['value']
59 | print ' CURRENT CONNECTIONS : %s' % nested_stats['serverside.curConns']['value']
60 | print ' MAXIMUM CONNECTIONS : %s' % nested_stats['serverside.maxConns']['value']
61 | print ' TOTAL CONNECTIONS : %s' % nested_stats['serverside.totConns']['value']
62 | print ' TOTAL REQUESTS : %s' % nested_stats['totRequests']['value']
63 |
64 |
65 |
66 | except Exception, e:
67 | print e
68 |
69 |
70 | def get_virtual_list(bigip, url):
71 | try:
72 | vips = bigip.get("%s/ltm/virtual" % url).json()
73 | print "VIRTUAL SERVER LIST"
74 | print " -------------------"
75 | for vip in vips['items']:
76 | print " /%s/%s" % (vip['partition'], vip['name'])
77 | except Exception, e:
78 | print e
79 |
80 |
81 | def get_virtual_stats(bigip, url, vip):
82 | try:
83 | vip_stats = bigip.get("%s/ltm/virtual/%s/stats" % (url, vip)).json()
84 | selflink = "https://localhost/mgmt/tm/ltm/virtual/%s/~Common~%s/stats" % (vip, vip)
85 | nested_stats = vip_stats['entries'][selflink]['nestedStats']['entries']
86 | print ''
87 | print ' --------------------------------------'
88 | print ' NAME : %s' % nested_stats['tmName']['description']
89 | print ' --------------------------------------'
90 | print ' AVAILABILITY STATE : %s' % nested_stats['status.availabilityState']['description']
91 | print ' ENABLED STATE : %s' % nested_stats['status.enabledState']['description']
92 | print ' REASON : %s' % nested_stats['status.statusReason']['description']
93 | print ' CLIENT BITS IN : %s' % nested_stats['clientside.bitsIn']['value']
94 | print ' CLIENT BITS OUT : %s' % nested_stats['clientside.bitsOut']['value']
95 | print ' CLIENT PACKETS IN : %s' % nested_stats['clientside.pktsIn']['value']
96 | print ' CLIENT PACKETS OUT : %s' % nested_stats['clientside.pktsOut']['value']
97 | print ' CURRENT CONNECTIONS : %s' % nested_stats['clientside.curConns']['value']
98 | print ' MAXIMUM CONNECTIONS : %s' % nested_stats['clientside.maxConns']['value']
99 | print ' TOTAL CONNECTIONS : %s' % nested_stats['clientside.totConns']['value']
100 | print ' TOTAL REQUESTS : %s' % nested_stats['totRequests']['value']
101 |
102 |
103 | except Exception, e:
104 | print e
105 |
106 |
107 | if __name__ == "__main__":
108 | import requests, json, argparse, getpass
109 | from requests.packages.urllib3.exceptions import InsecureRequestWarning
110 | requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
111 |
112 | parser = argparse.ArgumentParser(description='Get Pool or Virtual Statistics')
113 |
114 | parser.add_argument("host", help='BIG-IP IP or Hostname' )
115 | parser.add_argument("username", help='BIG-IP Username')
116 | parser.add_argument("type", help='pool|virtual ', nargs=2)
117 | args = vars(parser.parse_args())
118 |
119 | hostname = args['host']
120 | username = args['username']
121 | obj_type = args['type']
122 |
123 | print "%s, enter your password: " % username,
124 | password = getpass.getpass()
125 |
126 | b_url_base = 'https://%s/mgmt/tm' % hostname
127 | b = requests.session()
128 | b.auth = (username, password)
129 | b.verify = False
130 | b.headers.update({'Content-Type':'application/json'})
131 |
132 | if obj_type[0] == 'pool':
133 | if obj_type[1] == 'list':
134 | get_pool_list(b, b_url_base)
135 | else:
136 | get_pool_stats(b, b_url_base, obj_type[1])
137 |
138 | elif obj_type[0] == 'virtual':
139 | if obj_type[1] == 'list':
140 | get_virtual_list(b, b_url_base)
141 | else:
142 | get_virtual_stats(b, b_url_base, obj_type[1])
143 |
144 |
145 |
--------------------------------------------------------------------------------
/REST-DataGroup.js:
--------------------------------------------------------------------------------
1 | #!/usr/local/bin/node
2 |
3 | //=========================================================
4 | //
5 | //=========================================================
6 | var net = require('net');
7 | var stdio = require('stdio');
8 | var https = require('https');
9 | var net = require('net');
10 | var url = require('url');
11 | var request = require('request');
12 | var util = require('util');
13 |
14 | var ops = stdio.getopt({
15 | 'bigip' : { key: 'b', args: 1, description: 'BIG-IP address', default: 'bigip.joesmacbook.com'},
16 | 'user' : { key: 'u', args: 1, description: 'Username', default: 'admin'},
17 | 'pass' : { key: 'p', args: 1, description: 'Password', default: 'admin'},
18 | 'datagroup' : { key: 'g', args: 1, description: 'Data Group'},
19 | 'action' : { key: 'a', args: 1, description: 'Action [create|remove_from|add_to|delete]'},
20 | 'debug' : { key: 'd', description: 'Print Debug Messages'}
21 | });
22 |
23 | var BIGIP = ops.bigip;
24 | var USER = ops.user;
25 | var PASS = ops.pass;
26 | var POOL = ops.pool;
27 | var DATAGROUP = ops.datagroup;
28 | var ACTION = ops.action;
29 | var DEBUG = ops.debug;
30 |
31 | var args = ops.args;
32 |
33 |
34 | //--------------------------------------------------------
35 | function buildUrl(resource) {
36 | //--------------------------------------------------------
37 | return "https://" + BIGIP + resource;
38 | }
39 |
40 | //--------------------------------------------------------
41 | function getAuthToken(callback) {
42 | //--------------------------------------------------------
43 | var resource = "/mgmt/shared/authn/login";
44 | var user = USER;
45 | var pass = PASS;
46 | var body = "{'username':'" + user + "','password':'" + pass + "','loginProviderName':'tmos'}";
47 |
48 | httpRequest("POST", resource, body, user, pass, null, function(json) {
49 | var obj = JSON.parse(json);
50 | var token = obj["token"]["token"];
51 | callback(token);
52 | });
53 | }
54 |
55 | //--------------------------------------------------------
56 | function httpRequest(verb, resource, body, user, pass, token, callback) {
57 | //--------------------------------------------------------
58 |
59 | if ( DEBUG ) { console.log("\n: " + resource + ", verb=" + verb + "\n"); }
60 |
61 | var http_opts = {
62 | host: BIGIP,
63 | method: verb,
64 | port: 443,
65 | rejectUnauthorized: 0,
66 | path: resource
67 | };
68 |
69 | var http_headers = {
70 | 'Content-Type': 'application/json'
71 | };
72 |
73 | // Authentication Method
74 | if ( user && pass ) { http_opts["auth"] = user + ":" + pass; }
75 | else if ( token ) { http_headers["X-F5-Auth-Token"] = token; }
76 |
77 | // BODY?
78 | if ( body ) { http_headers["Content-Length"] = body.length; }
79 |
80 | http_opts["headers"] = http_headers;
81 |
82 | var content = "";
83 | var req = https.request(http_opts, function(res) {
84 | res.setEncoding("utf8");
85 | res.on('data', function(chunk) {
86 | content += chunk;
87 | }),
88 | res.on('end', function() {
89 | callback(content);
90 | })
91 | });
92 |
93 | req.on('error', function(e) {
94 | console.log("ERROR: " + JSON.stringify(e) + "\n");
95 | });
96 |
97 | if ( body ) {
98 | req.write(body + "\n");
99 | }
100 | req.end();
101 | }
102 |
103 |
104 | //--------------------------------------------------------
105 | function handleVERB(verb, resource, body, callback) {
106 | //--------------------------------------------------------
107 | getAuthToken( function(token) {
108 | httpRequest(verb, resource, body, null, null, token, function(json) {
109 | callback(json);
110 | });
111 | });
112 | }
113 |
114 |
115 | //--------------------------------------------------------
116 | function getDataGroupList() {
117 | //--------------------------------------------------------
118 | var uri = "/mgmt/tm/ltm/data-group/internal";
119 | handleVERB("GET", uri, null, function(json) {
120 | var obj = JSON.parse(json);
121 | var items = obj.items;
122 | var len = items.length;
123 | console.log("DATA GROUPS");
124 | console.log("==========");
125 | for(var i=0; i qw(method debug);
32 | use SOAP::Lite;
33 | use MIME::Base64;
34 | use Data::Dumper;
35 |
36 | $Data::Dumper::Deepcopy = 1;
37 |
38 | $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
39 |
40 | #----------------------------------------------------------------------------
41 | # Validate Arguments
42 | #----------------------------------------------------------------------------
43 | my $sHost = $ARGV[0];
44 | my $sUID = $ARGV[1];
45 | my $sPWD = $ARGV[2];
46 | my $sDataGroup = $ARGV[3];
47 | my $sAction = $ARGV[4];
48 |
49 | if ( ($sHost eq "") or ($sUID eq "") or ($sPWD eq "") )
50 | {
51 | die ("Usage: DataGroup.pl host uid pwd [datagroup action (create|remove_from_add_to|delete)]\n");
52 | }
53 |
54 | #----------------------------------------------------------------------------
55 | # Transport Information
56 | #----------------------------------------------------------------------------
57 | sub SOAP::Transport::HTTP::Client::get_basic_credentials
58 | {
59 | return "$sUID" => "$sPWD";
60 | }
61 |
62 | $Class = SOAP::Lite
63 | -> uri('urn:iControl:LocalLB/Class')
64 | -> proxy("https://$sHost/iControl/iControlPortal.cgi");
65 | eval { $Class->transport->http_request->header
66 | (
67 | 'Authorization' =>
68 | 'Basic ' . MIME::Base64::encode("$sUID:$sPWD", '')
69 | ); };
70 |
71 | if ( $sDataGroup eq "" ) {
72 | &getDataGroupList();
73 | } else {
74 | if ( $sAction eq "create" ) {
75 | &createDataGroup($sDataGroup);
76 | } elsif ( $sAction eq "remove_from" ) {
77 | &removeFromDataGroup($sDataGroup);
78 | } elsif ( $sAction eq "add_to" ) {
79 | &addToDataGroup($sDataGroup);
80 | } elsif ( $sAction eq "delete" ) {
81 | &deleteDataGroup($sDataGroup);
82 | } else {
83 | &getDataGroup($sDataGroup);
84 | }
85 | }
86 |
87 | #----------------------------------------------------------------------------
88 | sub checkResponse()
89 | #----------------------------------------------------------------------------
90 | {
91 | my ($soapResponse) = (@_);
92 | if ( $soapResponse->fault )
93 | {
94 | print $soapResponse->faultcode, " ", $soapResponse->faultstring, "\n";
95 | exit();
96 | }
97 | }
98 |
99 | #----------------------------------------------------------------------------
100 | sub getDataGroupList()
101 | #----------------------------------------------------------------------------
102 | {
103 |
104 | print "DATA GROUPS\n";
105 | print "-----------\n";
106 | $soapResponse = $Class->get_address_class_list();
107 | &checkResponse($soapResponse);
108 | @ClassList = @{$soapResponse->result};
109 | foreach $ClassName (@ClassList)
110 | {
111 | print " $ClassName - address\n";
112 | }
113 | $soapResponse = $Class->get_string_class_list();
114 | &checkResponse($soapResponse);
115 | @ClassList = @{$soapResponse->result};
116 | foreach $ClassName (@ClassList)
117 | {
118 | print " $ClassName - string\n";
119 | }
120 | $soapResponse = $Class->get_value_class_list();
121 | &checkResponse($soapResponse);
122 | @ClassList = @{$soapResponse->result};
123 | foreach $ClassName (@ClassList)
124 | {
125 | print " $ClassName - value\n";
126 | }
127 | }
128 |
129 | #----------------------------------------------------------------------------
130 | sub getDataGroup()
131 | #----------------------------------------------------------------------------
132 | {
133 | my ($datagroup) = @_;
134 | $soapResponse = $Class->get_string_class(
135 | SOAP::Data->name(class_names => [$datagroup])
136 | );
137 | my @StringClassA = @{$soapResponse->result};
138 |
139 | $soapResponse = $Class->get_string_class_member_data_value(
140 | SOAP::Data->name(class_members => [@StringClassA])
141 | );
142 | @DataValuesAofA = @{$soapResponse->result};
143 | @DataValuesA = @{$DataValuesAofA[0]};
144 |
145 | $len = scalar(@StringClassA);
146 | for ($i=0; $i < scalar(@StringClassA); $i++) {
147 | $StringClass = $StringClassA[$i];
148 | $DataValueA = $DataValueAofA[$i];
149 |
150 | $name = $StringClass->{"name"};
151 | @members = @{$StringClass->{"members"}};
152 |
153 | print "Data Group $name: [\n";
154 | for($j=0; $j < scalar(@members); $j++) {
155 | my $member = @members[$j];
156 | my $value = $DataValuesA[$j];
157 | print " { $member : $value }\n";
158 | }
159 | print "]\n";
160 | }
161 | }
162 |
163 | #----------------------------------------------------------------------------
164 | sub createDataGroup()
165 | #----------------------------------------------------------------------------
166 | {
167 | my ($datagroup) = @_;
168 |
169 | my @names = ("a", "b", "c");
170 |
171 | my $StringClass =
172 | {
173 | name => $datagroup,
174 | members => [@names]
175 | };
176 |
177 | # Create Data group with names
178 | $soapResponse = $Class->create_string_class(
179 | SOAP::Data->name(classes => [$StringClass])
180 | );
181 | &checkResponse($soapResponse);
182 |
183 | # Set values
184 | # Build Values 2-D Array for values parameter
185 | my @valuesA = ("data 1", "data 2", "data 3");
186 | my @valuesAofA;
187 | push @valuesAofA, [@valuesA];
188 | $soapResponse = $Class->set_string_class_member_data_value
189 | (
190 | SOAP::Data->name(class_members => [$StringClass]),
191 | SOAP::Data->name(values => [@valuesAofA])
192 | );
193 | &checkResponse($soapResponse);
194 |
195 | &getDataGroup($datagroup);
196 | }
197 |
198 | #----------------------------------------------------------------------------
199 | sub deleteDataGroup()
200 | #----------------------------------------------------------------------------
201 | {
202 | my ($datagroup) = @_;
203 |
204 | $soapResponse = $Class->delete_class(
205 | SOAP::Data->name(classes => [$datagroup])
206 | );
207 | &checkResponse($soapResponse);
208 |
209 | print "Data group $datagroup deleted...\n";
210 | }
211 |
212 | #----------------------------------------------------------------------------
213 | sub removeFromDataGroup()
214 | #----------------------------------------------------------------------------
215 | {
216 | my ($datagroup) = @_;
217 |
218 | my @names = ("c");
219 |
220 | my $StringClass =
221 | {
222 | name => $datagroup,
223 | members => [@names]
224 | };
225 |
226 | # Create Data group with names
227 | $soapResponse = $Class->delete_string_class_member(
228 | SOAP::Data->name(class_members => [$StringClass])
229 | );
230 | &checkResponse($soapResponse);
231 |
232 | &getDataGroup($datagroup);
233 | }
234 |
235 | #----------------------------------------------------------------------------
236 | sub addToDataGroup()
237 | #----------------------------------------------------------------------------
238 | {
239 | my ($datagroup) = @_;
240 |
241 | my @names = ("d", "e");
242 |
243 | my $StringClass =
244 | {
245 | name => $datagroup,
246 | members => [@names]
247 | };
248 |
249 | # Create Data group with names
250 | $soapResponse = $Class->add_string_class_member(
251 | SOAP::Data->name(class_members => [$StringClass])
252 | );
253 | &checkResponse($soapResponse);
254 |
255 | # Set values
256 | # Build Values 2-D Array for values parameter
257 | my @valuesA = ("data 4", "data 5");
258 | my @valuesAofA;
259 | push @valuesAofA, [@valuesA];
260 | $soapResponse = $Class->set_string_class_member_data_value
261 | (
262 | SOAP::Data->name(class_members => [$StringClass]),
263 | SOAP::Data->name(values => [@valuesAofA])
264 | );
265 | &checkResponse($soapResponse);
266 |
267 | &getDataGroup($datagroup);
268 | }
269 |
270 |
271 |
--------------------------------------------------------------------------------
/REST-Stats.js:
--------------------------------------------------------------------------------
1 | #!/usr/local/bin/node
2 |
3 | //=========================================================
4 | //
5 | //=========================================================
6 | var net = require('net');
7 | var stdio = require('stdio');
8 | var https = require('https');
9 | var net = require('net');
10 | var url = require('url');
11 | var request = require('request');
12 | var util = require('util');
13 |
14 | var ops = stdio.getopt({
15 | 'bigip' : { key: 'b', args: 1, description: 'BIG-IP address', default: 'bigip.joesmacbook.com'},
16 | 'user' : { key: 'u', args: 1, description: 'Username', default: 'admin'},
17 | 'pass' : { key: 'p', args: 1, description: 'Password', default: 'admin'},
18 | 'type' : { key: 'g', args: 1, description: 'Object Type: [virtual|poo]'},
19 | 'name' : { key: 'a', args: 1, description: 'Object Name'},
20 | 'debug' : { key: 'd', description: 'Print Debug Messages'}
21 | });
22 |
23 | var BIGIP = ops.bigip;
24 | var USER = ops.user;
25 | var PASS = ops.pass;
26 | var TYPE = ops.type;
27 | var NAME = ops.name;
28 | var DEBUG = ops.debug;
29 |
30 | var args = ops.args;
31 |
32 |
33 | //--------------------------------------------------------
34 | function buildUrl(resource) {
35 | //--------------------------------------------------------
36 | return "https://" + BIGIP + resource;
37 | }
38 |
39 | //--------------------------------------------------------
40 | function getAuthToken(callback) {
41 | //--------------------------------------------------------
42 | var resource = "/mgmt/shared/authn/login";
43 | var user = USER;
44 | var pass = PASS;
45 | var body = "{'username':'" + user + "','password':'" + pass + "','loginProviderName':'tmos'}";
46 |
47 | httpRequest("POST", resource, body, user, pass, null, function(json) {
48 | var obj = JSON.parse(json);
49 | var token = obj["token"]["token"];
50 | callback(token);
51 | });
52 | }
53 |
54 | //--------------------------------------------------------
55 | function httpRequest(verb, resource, body, user, pass, token, callback) {
56 | //--------------------------------------------------------
57 |
58 | if ( DEBUG ) { console.log("\n: " + resource + ", verb=" + verb + "\n"); }
59 |
60 | var http_opts = {
61 | host: BIGIP,
62 | method: verb,
63 | port: 443,
64 | rejectUnauthorized: 0,
65 | path: resource
66 | };
67 |
68 | var http_headers = {
69 | 'Content-Type': 'application/json'
70 | };
71 |
72 | // Authentication Method
73 | if ( user && pass ) { http_opts["auth"] = user + ":" + pass; }
74 | else if ( token ) { http_headers["X-F5-Auth-Token"] = token; }
75 |
76 | // BODY?
77 | if ( body ) { http_headers["Content-Length"] = body.length; }
78 |
79 | http_opts["headers"] = http_headers;
80 |
81 | var content = "";
82 | var req = https.request(http_opts, function(res) {
83 | res.setEncoding("utf8");
84 | res.on('data', function(chunk) {
85 | content += chunk;
86 | }),
87 | res.on('end', function() {
88 | callback(content);
89 | })
90 | });
91 |
92 | req.on('error', function(e) {
93 | console.log("ERROR: " + JSON.stringify(e) + "\n");
94 | });
95 |
96 | if ( body ) {
97 | req.write(body + "\n");
98 | }
99 | req.end();
100 | }
101 |
102 |
103 | //--------------------------------------------------------
104 | function handleVERB(verb, resource, body, callback) {
105 | //--------------------------------------------------------
106 | getAuthToken( function(token) {
107 | httpRequest(verb, resource, body, null, null, token, function(json) {
108 | callback(json);
109 | });
110 | });
111 | }
112 |
113 | //--------------------------------------------------------
114 | function getVirtualList(name) {
115 | //--------------------------------------------------------
116 | var uri = "/mgmt/tm/ltm/virtual";
117 |
118 | handleVERB("GET", uri, null, function(json) {
119 | //console.log(json);
120 | var obj = JSON.parse(json);
121 | var items = obj.items;
122 | console.log("VIRTUALS");
123 | console.log("-----------");
124 | for(var i=0; i 3 )
77 | {
78 | datagroup = args[3];
79 | }
80 | if ( args.length > 4 )
81 | {
82 | action = args[4];
83 | }
84 |
85 | // build parameters
86 | m_interfaces.initialize(bigip, port, user, pass);
87 |
88 | if ( null == datagroup ) {
89 | getDataGroupList();
90 | } else {
91 | if ( null == action ) {
92 | getDataGroup(datagroup);
93 | } else if ( action.equals("create") ) {
94 | createDataGroup(datagroup);
95 | } else if ( action.equals("delete") ) {
96 | deleteDataGroup(datagroup);
97 | } else if ( action.equals("remove_from") ) {
98 | removeFromDataGroup(datagroup);
99 | } else if ( action.equals("add_to") ) {
100 | addToDataGroup(datagroup);
101 | } else {
102 | getDataGroup(datagroup);
103 | }
104 |
105 | }
106 |
107 | bSuccess = true;
108 | }
109 |
110 | return bSuccess;
111 | }
112 |
113 | //--------------------------------------------------------------------------
114 | //
115 | //--------------------------------------------------------------------------
116 | public void usage()
117 | {
118 | System.out.println("Usage: SOAPDataGroup hostname username password [pool partition]");
119 | }
120 |
121 |
122 | //--------------------------------------------------------------------------
123 | //
124 | //--------------------------------------------------------------------------
125 | public void getDataGroupList() throws Exception
126 | {
127 | System.out.println("Data Groups");
128 | System.out.println("-----------");
129 | String [] pool_list = m_interfaces.getLocalLBClass().get_address_class_list();
130 | for(int i=0; inew->allow_nonref;
17 |
18 | my $BIGIP = "";
19 | my $USER = "";
20 | my $PASS = "";
21 | my $DATAGROUP = "";
22 | my $ACTION = "";
23 | my $AUTH_TOKEN = "";
24 | my $RESOURCE = "";
25 | my $DEBUG = 0;
26 |
27 | GetOptions(
28 | 'bigip=s' => \$BIGIP,
29 | "user=s" => \$USER,
30 | "pass=s" => \$PASS,
31 | "user=s" => \$USER,
32 | "datagroup=s" => \$DATAGROUP,
33 | "action=s" => \$ACTION,
34 | "debug" => \$DEBUG
35 | );
36 |
37 | sub usage() {
38 | print "Usage: REST-DataGroup.pl [options] \n";
39 | print " options\n";
40 | print " ----------------\n";
41 | print " --bigip bigip_addr\n";
42 | print " --user bigip_username\n";
43 | print " --pass bigip_password\n";
44 | print " --datagroup dg_name\n";
45 | print " --action [create|remove_from|add_to|delete]\n";
46 | print "\n";
47 | exit();
48 | };
49 |
50 | #---------------------------------------------------
51 | sub getAuthToken() {
52 | #---------------------------------------------------
53 | $url = "https://${BIGIP}/mgmt/shared/authn/login";
54 | $user = $USER;
55 | $pass = $PASS;
56 |
57 | $body = "{'username':'$user','password':'$pass','loginProviderName':'tmos'}";
58 |
59 | $json = httpRequestWithBody("POST", $url, $body, 1);
60 |
61 | $obj = decode_json($json);
62 | $AUTH_TOKEN = $obj->{token}->{token};
63 |
64 | if ( $DEBUG ) {
65 | print "TOKEN: $AUTH_TOKEN\n";
66 | }
67 |
68 | return $AUTH_TOKEN;
69 | }
70 |
71 | #---------------------------------------------------
72 | sub httpRequestWithoutBody() {
73 | #---------------------------------------------------
74 | my ($verb, $url) = (@_);
75 |
76 | if ( $DEBUG ) {
77 | print "REQUESTING URL : ${url} ${verb}\n";
78 | }
79 |
80 | $content = "";
81 | if ( $url ) {
82 | my $ua = LWP::UserAgent->new;
83 | my $req;
84 | if ( $verb eq "DELETE" ) {
85 | $req = HTTP::Request->new(DELETE => $url);
86 | } else {
87 | $req = HTTP::Request->new(GET => $url);
88 | }
89 | #$req->authorization_basic($USER, $PASS);
90 | my $auth_token = &getAuthToken();
91 | if ( "" ne $auth_token ) {
92 | $req->header("X-F5-Auth-Token" => $auth_token);
93 | }
94 |
95 | $resp = $ua->request($req);
96 | if ( $DEBUG ) {
97 | print Dumper($resp);
98 | }
99 |
100 | if ( $resp->is_success ) {
101 | $content = $resp->content;
102 | #print "CONTENT: ${content}\n";
103 | } else {
104 | $code = $resp->code;
105 | $msg = $resp->message;
106 | $content = $resp->content;
107 | die "HTTP ERROR ${code} : \"${msg}\" : \"${content}\"\n";
108 | }
109 | }
110 | return $content;
111 | }
112 |
113 | #---------------------------------------------------
114 | sub httpRequestWithBody() {
115 | #---------------------------------------------------
116 | my ($verb, $url, $body, $basicauth) = (@_);
117 |
118 | if ( $DEBUG ) {
119 | print "REQUESTING URL (POST) : ${url}\n";
120 | }
121 |
122 | $content = "";
123 | if ( $url ) {
124 | my $ua = LWP::UserAgent->new;
125 |
126 | my $req;
127 | if ( $verb eq "PUT" ) {
128 | $req = HTTP::Request->new(PUT => $url);
129 | } elsif ( $verb eq "PATCH" ) {
130 | $req = HTTP::Request->new(PATCH => $url);
131 | } else {
132 | $req = HTTP::Request->new(POST => $url);
133 | }
134 |
135 | if ( $basicauth == 1 ) {
136 | $req->authorization_basic($USER, $PASS);
137 | } else {
138 | my $auth_token = &getAuthToken();
139 | if ( "" ne $auth_token ) {
140 | $req->header("X-F5-Auth-Token" => $auth_token);
141 | }
142 | }
143 |
144 | $req->header("Content-Type" => "application/json");
145 | $req->content($body);
146 |
147 | $resp = $ua->request($req);
148 | if ( $DEBUG ) {
149 | print Dumper($resp);
150 | }
151 |
152 | if ( $resp->is_success ) {
153 | $content = $resp->content;
154 | #print "CONTENT: ${content}\n";
155 | } else {
156 | $code = $resp->code;
157 | $msg = $resp->message;
158 | $content = $resp->content;
159 | die "HTTP ERROR ${code} : \"${msg}\" : \"${content}\"\n";
160 | }
161 | }
162 | return $content;
163 | }
164 |
165 | #---------------------------------------------------
166 | sub buildURL() {
167 | #---------------------------------------------------
168 | my ($resource) = @_;
169 |
170 | $url = "https://${BIGIP}/$resource";
171 |
172 | return $url;
173 | }
174 |
175 | #---------------------------------------------------
176 | sub handleGET() {
177 | #---------------------------------------------------
178 | my ($resource) = @_;
179 |
180 | $url = &buildURL($resource);
181 |
182 | $resp = &httpRequestWithoutBody("GET", $url);
183 |
184 | return $resp;
185 | }
186 |
187 | #---------------------------------------------------
188 | sub handleDELETE() {
189 | #---------------------------------------------------
190 | my ($resource) = @_;
191 |
192 | $url = &buildURL($resource);
193 |
194 | $resp = &httpRequestWithoutBody("DELETE", $url);
195 |
196 | return $resp;
197 | }
198 |
199 | #---------------------------------------------------
200 | sub handlePOST() {
201 | #---------------------------------------------------
202 | my ($resource, $body) = @_;
203 |
204 | if ( $body eq "" ) { &usage(); }
205 |
206 | $url = &buildURL($resource);
207 |
208 | $resp = &httpRequestWithBody("POST", $url, $body);
209 |
210 | return $resp;
211 | }
212 |
213 | #---------------------------------------------------
214 | sub handlePUT() {
215 | #---------------------------------------------------
216 | my ($resource, $body) = @_;
217 |
218 | if ( $body eq "" ) { &usage(); }
219 |
220 | $url = &buildURL($resource);
221 |
222 | $resp = &httpRequestWithBody("PUT", $url, $body);
223 |
224 | return $resp;
225 | }
226 |
227 | #---------------------------------------------------
228 | sub handlePATCH() {
229 | #---------------------------------------------------
230 | my ($resource, $body) = @_;
231 |
232 | if ( $body eq "" ) { &usage(); }
233 |
234 | $url = &buildURL($resource);
235 |
236 | $resp = &httpRequestWithBody("PATCH", $url, $body);
237 |
238 | return $resp;
239 | }
240 |
241 | #---------------------------------------------------
242 | sub getDataGroupList() {
243 | #---------------------------------------------------
244 | $uri = "/mgmt/tm/ltm/data-group/internal";
245 | $resp_json = &handleGET($uri);
246 | $resp = decode_json($resp_json);
247 | @items = @{$resp->{"items"}};
248 |
249 | print "DATA GROUPS\n";
250 | print "----------\n";
251 | foreach $item (@items) {
252 | $fullPath = $item->{"fullPath"};
253 | print " $fullPath\n";
254 | #print "-----------------------------------\n";
255 | #print Dumper($item);
256 | #print "-----------------------------------\n";
257 | }
258 | }
259 |
260 | #---------------------------------------------------
261 | sub getDataGroup() {
262 | #---------------------------------------------------
263 | my ($datagroup) = @_;
264 | $datagroup =~ s/\//~/g;
265 | my $uri = "/mgmt/tm/ltm/data-group/internal/${datagroup}";
266 | $resp_json = &handleGET($uri);
267 | $resp = decode_json($resp_json);
268 |
269 | print Dumper($resp);
270 | }
271 |
272 | #---------------------------------------------------
273 | sub createDataGroup() {
274 | #---------------------------------------------------
275 | my ($datagroup) = @_;
276 |
277 | print "CREATE DATA GROUP\n";
278 |
279 | my $uri = "/mgmt/tm/ltm/data-group/internal";
280 |
281 | my $dgObj;
282 | $dgObj->{"name"} = $datagroup;
283 | $dgObj->{"type"} = "string";
284 |
285 | $dgObj->{"records"} = [
286 | { name => 'a', data => 'data 1' },
287 | { name => 'b', data => 'data 2' },
288 | { name => 'c', data => 'data 3' }
289 | ];
290 |
291 | my $json = encode_json($dgObj);
292 |
293 | $resp = &handlePOST($uri, $json);
294 | print Dumper($resp);
295 | }
296 |
297 | #---------------------------------------------------
298 | sub deleteDataGroup($DATAGROUP) {
299 | #---------------------------------------------------
300 | my ($datagroup) = @_;
301 |
302 | $datagroup =~ s/\//~/g;
303 | $uri = "/mgmt/tm/ltm/data-group/internal/${datagroup}";
304 |
305 | $resp = &handleDELETE($uri);
306 | print Dumper($resp);
307 | }
308 |
309 | #---------------------------------------------------
310 | sub removeFromDataGroup($DATAGROUP) {
311 | #---------------------------------------------------
312 | my ($datagroup) = @_;
313 |
314 | $datagroup =~ s/\//~/g;
315 | $uri = "/mgmt/tm/ltm/data-group/internal/${datagroup}";
316 |
317 | my $dgObj;
318 | $dgObj->{"name"} = $datagroup;
319 |
320 | $dgObj->{"records"} = [
321 | { name => 'a', data => 'data 1' },
322 | { name => 'b', data => 'data 2' }
323 | ];
324 |
325 | my $json = encode_json($dgObj);
326 |
327 | $resp = &handlePATCH($uri, $json);
328 | print Dumper($resp);
329 |
330 | }
331 |
332 | #---------------------------------------------------
333 | sub addToDataGroup($DATAGROUP) {
334 | #---------------------------------------------------
335 | my ($datagroup) = @_;
336 |
337 | $datagroup =~ s/\//~/g;
338 | $uri = "/mgmt/tm/ltm/data-group/internal/${datagroup}";
339 |
340 | my $dgObj;
341 | $dgObj->{"name"} = $datagroup;
342 |
343 | $dgObj->{"records"} = [
344 | { name => 'a', data => 'data 1' },
345 | { name => 'b', data => 'data 2' },
346 | { name => 'd', data => 'data 4' },
347 | { name => 'e', data => 'data 5' }
348 | ];
349 |
350 | my $json = encode_json($dgObj);
351 |
352 | $resp = &handlePUT($uri, $json);
353 | print Dumper($resp);
354 |
355 | }
356 |
357 | #===================================================
358 |
359 | #===================================================
360 |
361 |
362 | if ( ($BIGIP eq "") || ($USER eq "") || ($PASS eq "") ) {
363 | &usage();
364 | } else {
365 | if ( $DATAGROUP eq "" ) {
366 | &getDataGroupList();
367 | } else {
368 | if ( $ACTION eq "create" ) {
369 | &createDataGroup($DATAGROUP);
370 | } elsif ( $ACTION eq "remove_from" ) {
371 | &removeFromDataGroup($DATAGROUP);
372 | } elsif ( $ACTION eq "add_to" ) {
373 | &addToDataGroup($DATAGROUP);
374 | } elsif ( $ACTION eq "delete" ) {
375 | &deleteDataGroup($DATAGROUP);
376 | } else {
377 | &getDataGroup($DATAGROUP);
378 | }
379 | }
380 | }
381 |
--------------------------------------------------------------------------------
/REST-Stats.ps1:
--------------------------------------------------------------------------------
1 | #----------------------------------------------------------------------------
2 | # The contents of this file are subject to the "END USER LICENSE AGREEMENT
3 | # FOR F5 Software Development Kit for iControl"; you may not use this file
4 | # except in compliance with the License. The License is included in the
5 | # iControl Software Development Kit.
6 | #
7 | # Software distributed under the License is distributed on an "AS IS"
8 | # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9 | # the License for the specific language governing rights and limitations
10 | # under the License.
11 | #
12 | # The Original Code is iControl Code and related documentation
13 | # distributed by F5.
14 | #
15 | # The Initial Developer of the Original Code is F5 Networks,
16 | # Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2009
17 | # F5 Networks, Inc. All Rights Reserved. iControl (TM) is a registered
18 | # trademark of F5 Networks, Inc.
19 | #
20 | # Alternatively, the contents of this file may be used under the terms
21 | # of the GNU General Public License (the "GPL"), in which case the
22 | # provisions of GPL are applicable instead of those above. If you wish
23 | # to allow use of your version of this file only under the terms of the
24 | # GPL and not to allow others to use your version of this file under the
25 | # License, indicate your decision by deleting the provisions above and
26 | # replace them with the notice and other provisions required by the GPL.
27 | # If you do not delete the provisions above, a recipient may use your
28 | # version of this file under either the License or the GPL.
29 | #----------------------------------------------------------------------------
30 | param(
31 | [string]$Bigip = "",
32 | [string]$User = "",
33 | [string]$Pass = "",
34 | [string]$Type = "",
35 | [string]$Name = ""
36 | );
37 |
38 | #----------------------------------------------------------------------------
39 | function Get-StatsValue()
40 | #
41 | # Description:
42 | # This function extracts a named property from an object
43 | #----------------------------------------------------------------------------
44 | {
45 | param($obj, $prop);
46 | return ($obj.entries | Select -ExpandProperty $prop).value
47 | }
48 |
49 | #----------------------------------------------------------------------------
50 | function Get-StatsDescription()
51 | #
52 | # Description:
53 | # This function extracts a named description from an object
54 | #----------------------------------------------------------------------------
55 | {
56 | param($obj, $prop);
57 | return ($obj.entries | Select -ExpandProperty $prop).description
58 | }
59 |
60 | #----------------------------------------------------------------------------
61 | function Get-VirtualList()
62 | #
63 | # Description:
64 | # This function lists all virtual servers.
65 | #
66 | # Parameters:
67 | # None
68 | #----------------------------------------------------------------------------
69 | {
70 | $uri = "/mgmt/tm/ltm/virtual";
71 | $link = "https://$Bigip$uri";
72 | $headers = @{};
73 | $headers.Add("ServerHost", $Bigip);
74 |
75 | $secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
76 | $mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
77 |
78 | $obj = Invoke-RestMethod -Method GET -Headers $headers -Uri $link -Credential $mycreds
79 | $items = $obj.items;
80 | Write-Host "POOL NAMES";
81 | Write-Host "----------";
82 | for($i=0; $i -lt $items.length; $i++) {
83 | $name = $items[$i].fullPath;
84 | Write-Host " $name";
85 | }
86 | }
87 |
88 | #----------------------------------------------------------------------------
89 | function Get-VirtualStats()
90 | #
91 | # Description:
92 | # This function returns the statistics for a virtual server
93 | #
94 | # Parameters:
95 | # Name - The name of the virtual server
96 | #----------------------------------------------------------------------------
97 | {
98 | param(
99 | [string]$Name
100 | );
101 | $uri = "/mgmt/tm/ltm/virtual/${Name}/stats";
102 |
103 | $link = "https://$Bigip$uri";
104 | $headers = @{};
105 | $headers.Add("ServerHost", $Bigip);
106 |
107 | $secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
108 | $mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
109 |
110 | $obj = Invoke-RestMethod -Method GET -Headers $headers -Uri $link -Credential $mycreds
111 |
112 | $entries = $obj.entries;
113 | $names = $entries | get-member -MemberType NoteProperty | select -ExpandProperty Name;
114 |
115 | $desc = $entries | Select -ExpandProperty $names
116 | $nestedStats = $desc.nestedStats;
117 |
118 | Write-Host ("--------------------------------------");
119 | Write-Host ("NAME : $(Get-StatsDescription $nestedStats 'tmName')");
120 | Write-Host ("--------------------------------------");
121 | Write-Host ("DESTINATION : $(Get-StatsDescription $nestedStats 'destination')");
122 | Write-Host ("AVAILABILITY STATE : $(Get-StatsDescription $nestedStats 'status.availabilityState')");
123 | Write-Host ("ENABLED STATE : $(Get-StatsDescription $nestedStats 'status.enabledState')");
124 | Write-Host ("REASON : $(Get-StatsDescription $nestedStats 'status.statusReason')");
125 | Write-Host ("CLIENT BITS IN : $(Get-StatsValue $nestedStats 'clientside.bitsIn')");
126 | Write-Host ("CLIENT BITS OUT : $(Get-StatsValue $nestedStats 'clientside.bitsOut')");
127 | Write-Host ("CLIENT PACKETS IN : $(Get-StatsValue $nestedStats 'clientside.pktsIn')");
128 | Write-Host ("CLIENT PACKETS OUT : $(Get-StatsValue $nestedStats 'clientside.pktsOut')");
129 | Write-Host ("CURRENT CONNECTIONS : $(Get-StatsValue $nestedStats 'clientside.curConns')");
130 | Write-Host ("MAXIMUM CONNECTIONS : $(Get-StatsValue $nestedStats 'clientside.maxConns')");
131 | Write-Host ("TOTAL CONNECTIONS : $(Get-StatsValue $nestedStats 'clientside.totConns')");
132 | Write-Host ("TOTAL REQUESTS : $(Get-StatsValue $nestedStats 'totRequests')");
133 | }
134 |
135 | #----------------------------------------------------------------------------
136 | function Get-PoolList()
137 | #
138 | # Description:
139 | # This function returns the list of pools
140 | #
141 | # Parameters:
142 | # None
143 | #----------------------------------------------------------------------------
144 | {
145 | $uri = "/mgmt/tm/ltm/pool";
146 | $link = "https://$Bigip$uri";
147 | $headers = @{};
148 | $headers.Add("ServerHost", $Bigip);
149 |
150 | $secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
151 | $mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
152 |
153 | $obj = Invoke-RestMethod -Method GET -Headers $headers -Uri $link -Credential $mycreds
154 | $items = $obj.items;
155 | Write-Host "POOL NAMES";
156 | Write-Host "----------";
157 | for($i=0; $i -lt $items.length; $i++) {
158 | $name = $items[$i].fullPath;
159 | Write-Host " $name";
160 | }
161 | }
162 |
163 | #----------------------------------------------------------------------------
164 | function Get-PoolStats()
165 | #
166 | # Description:
167 | # This function returns the statistics for a pool
168 | #
169 | # Parameters:
170 | # Name - The name of the pool
171 | #----------------------------------------------------------------------------
172 | {
173 | $uri = "/mgmt/tm/ltm/pool/${Name}/stats";
174 |
175 | $link = "https://$Bigip$uri";
176 | $headers = @{};
177 | $headers.Add("ServerHost", $Bigip);
178 |
179 | $secpasswd = ConvertTo-SecureString $Pass -AsPlainText -Force
180 | $mycreds = New-Object System.Management.Automation.PSCredential ($User, $secpasswd)
181 |
182 | $obj = Invoke-RestMethod -Method GET -Headers $headers -Uri $link -Credential $mycreds
183 |
184 | $entries = $obj.entries;
185 | $names = $entries | get-member -MemberType NoteProperty | select -ExpandProperty Name;
186 |
187 | $desc = $entries | Select -ExpandProperty $names
188 | $nestedStats = $desc.nestedStats;
189 |
190 | Write-Host ("--------------------------------------");
191 | Write-Host ("NAME : $(Get-StatsDescription $nestedStats 'tmName')");
192 | Write-Host ("--------------------------------------");
193 | Write-Host ("AVAILABILITY STATE : $(Get-StatsDescription $nestedStats 'status.availabilityState')");
194 | Write-Host ("ENABLED STATE : $(Get-StatsDescription $nestedStats 'status.enabledState')");
195 | Write-Host ("REASON : $(Get-StatsDescription $nestedStats 'status.statusReason')");
196 | Write-Host ("SERVER BITS IN : $(Get-StatsValue $nestedStats 'serverside.bitsIn')");
197 | Write-Host ("SERVER BITS OUT : $(Get-StatsValue $nestedStats 'serverside.bitsOut')");
198 | Write-Host ("SERVER PACKETS IN : $(Get-StatsValue $nestedStats 'serverside.pktsIn')");
199 | Write-Host ("SERVER PACKETS OUT : $(Get-StatsValue $nestedStats 'serverside.pktsOut')");
200 | Write-Host ("CURRENT CONNECTIONS : $(Get-StatsValue $nestedStats 'serverside.curConns')");
201 | Write-Host ("MAXIMUM CONNECTIONS : $(Get-StatsValue $nestedStats 'serverside.maxConns')");
202 | Write-Host ("TOTAL CONNECTIONS : $(Get-StatsValue $nestedStats 'serverside.totConns')");
203 | Write-Host ("TOTAL REQUESTS : $(Get-StatsValue $nestedStats 'totRequests')");
204 | }
205 |
206 | #----------------------------------------------------------------------------
207 | function Show-Usage()
208 | #
209 | # Description:
210 | # This function will print the script usage information.
211 | #
212 | #----------------------------------------------------------------------------
213 | {
214 | Write-Host @"
215 | Usage: CreatePoolInPartition.ps1 Arguments
216 | Argument - Description
217 | ---------- -----------
218 | Bigip - The ip/hostname of your BIG-IP.
219 | User - The Managmenet username for your BIG-IP.
220 | Pass - The Management password for your BIG-IP.
221 | Type - The type of object [virtual|pool].
222 | Name - The name of the object to get stats for.
223 | "@;
224 | }
225 |
226 | #============================================================================
227 | # Main application logic
228 | #============================================================================
229 | if ( ($Bigip.Length -eq 0) -or ($User.Length -eq 0) -or ($Pass.Length -eq 0) -or ($Type.Length -eq 0) ) {
230 | Show-Usage;
231 | } elseif ( $Type -eq "virtual" ) {
232 | if ( $Name.Length -eq 0 ) {
233 | Get-VirtualList;
234 | } else {
235 | Get-VirtualStats -Name $Name;
236 | }
237 | } elseif ( $Type -eq "pool" ) {
238 | if ( $Name.Length -eq 0 ) {
239 | Get-PoolList;
240 | } else {
241 | Get-PoolStats -Name $Name;
242 | }
243 | }
244 |
--------------------------------------------------------------------------------