Apr 18 2020

Jenkins Slave Auto Register with REST API

Published by under Jenkins

Create a Jenkins node automatically with a REST API call. Most of the work is to build some json code that describes the new Jenkins slave. The configuration can be slightly different depending on the node settings you are willing to apply. To get exactly what you want, you may create a dummy slave manually and capture the JSON object in your browser developer tool’s network tab while you click on “Save”. In the meantime, here’s mine, assuming agent launches with a startup script:

{
   "name": "my_jenkins_slave",
   "nodeDescription": "my Jenkins slave",
   "numExecutors": "2",
   "remoteFS": "/home/jenkins",
   "labelString": "slave",
   "mode": "EXCLUSIVE",
   "": [
      "hudson.slaves.JNLPLauncher",
      "hudson.slaves.RetentionStrategy$Always"
   ],
   "launcher": {
      "stapler-class": "hudson.slaves.JNLPLauncher",
      "$class": "hudson.slaves.JNLPLauncher",
      "workDirSettings": {
         "disabled": true,
         "workDirPath": "",
         "internalDir": "remoting",
         "failIfWorkDirIsMissing": false
      },
      "tunnel": "",
      "vmargs": ""
   },
   "retentionStrategy": {
      "stapler-class": "hudson.slaves.RetentionStrategy$Always",
      "$class": "hudson.slaves.RetentionStrategy$Always"
   },
   "nodeProperties": {
      "stapler-class-bag": "true",
      "hudson-slaves-EnvironmentVariablesNodeProperty": {
         "env": [
            {
               "key": "JAVA_HOME",
               "value": "/usr/lib/jvm/java-8-openjdk-amd64"
            }
         ]
      },
      "_comment:": {
         "hudson-tools-ToolLocationNodeProperty": {
           "locations": [
               {
                  "key": "hudson.model.JDK$DescriptorImpl@JAVA-8",
                  "home": "/usr/bin/java"
               }
            ]
         }
      }
   }
}


All you need is define the following variables:

jenkins_user=my_jenkins_user
jenkins_token=my_jenkins_token
jenkins_url=https://jenkins.mydomain.lan


And post the JSON file with a simple curl:

$ curl -L -s -o /dev/null -w "%{http_code}" -u $jenkins_user:$jenkins_token \
-H "Content-Type:application/x-www-form-urlencoded" -X POST \
-d "json=$(cat /tmp/node.json)" \
"$jenkins_url/computer/doCreateItem?name=my_jenkins_slave&type=hudson.slaves.DumbSlave"; \
echo
200


If you do not get a 200 response code, run the same skipping “-o /dev/null” to troubleshoot.
Some say you may do the same with different tools like Jenkins CLI or some plugins but Jenkins REST API works through any firewall and is pretty easy to set up.
In the next post, I’ll use this method to automate Jenkins agent registration with Ansible

 

No responses yet

May 17 2018

Browser Driver has Received Too many Illegal Datagrams

Published by under AS400

I was getting tons of events ID 8016 labelled “bowser” in the Windows system event log. These are generated by IBM i (AS400) servers:
 
“The browser driver has received too many illegal datagrams from the remote computer AS400 to name DOMAIN on transport NetBT_Tcpip_{356179F8-4CA4-48CA-92C2-AFEA87D1F884}. The data is the datagram. No more events will be generated until the reset frequency has expired.”
 
Here’s how to get rid of them:
Open Navigator for i
Browse Network, Servers, TCP/IP Servers
Select IBM i NetServer, clic on the Actions tab and select Properties
 

 
In the new window, go into the Advanced tab, click on “Next Start”
and untick “Send browse announcements”
 

 

No responses yet

Jul 05 2017

Auto Update Devices in GLPI

Published by under GLPI

Having loads of physical sites, it is extremely difficult to keep track of device’s locations, and even if you do, you may not be aware some people moved computers or printers around to a new place without telling; It can also be useful to know where a device was last seen.
 
Requirements:
– Add network switches in GLPI making sure Name (DNS name), brand, location and type fields are filled in
– Generate an SSH key pair on the server from where you are going to run the script, install the public key on the switches so you can log on automatically on each one of them
Supported switches include Cisco Catalyst, HP Procurve* and 3com but could be ported easily to other brands.
Check Cisco, HP and 3com official documentation to install the public key on each device.
– Edit GLPI settings (in the script) and run the script
 

 
Features:
– Gets the switch list from GLPI (registered as “switch” in network devices)
– Connects to the switches and gets a list of mac addresses
– If the mac is found in GLPI (within Computer, Printers or Network devices), updates Last modified date and location
– If not, gets the mac’s vendor from Internet. A cache makes it faster if the 6 digits were found before
– Tells percentage of known macs
– tells if duplicates are found in GLPI (mac found on the network matching multiple devices in GLPI)
– Works on Cisco, HP* and 3com switches and could be easily modified for other brands that support SSH auto-connect. Some gears like Cisco Small Business don’t support it.
% gets better as you register more and more macs in GLPI
You have no idea how many devices connect to the network!

* in combination with rancid

Download for free

 

No responses yet

Next »