{"id":406,"date":"2021-10-25T09:02:50","date_gmt":"2021-10-25T15:02:50","guid":{"rendered":"https:\/\/www.scottharvanek.com\/?p=406"},"modified":"2022-03-10T09:06:40","modified_gmt":"2022-03-10T15:06:40","slug":"rev-io-and-netbox","status":"publish","type":"post","link":"https:\/\/www.scottharvanek.com\/?p=406","title":{"rendered":"Rev.IO and Netbox&#8230;"},"content":{"rendered":"\n<p><a href=\"https:\/\/rev.io\">Rev.IO<\/a> has kind of a terrible asset management interface, (and they&#8217;ve killed their WWW subdomain without a redirect,&#8230; but that&#8217;s another rant) but we&#8217;ve chosen it due to its ability to handle MSP billing, so while it&#8217;s not ideal it&#8217;s something that my team has to work with.  <\/p>\n\n\n\n<p>So our first task was taking all of the Inventory that was in <a href=\"https:\/\/rev.io\">Rev.IO<\/a> which as been transitioned into being our asset management platform as well since inventory is tracked in Rev.IO for billing purposes it does not make sense to use another platform given our small volume.  The issue lies in how Rev.IO does its asset management and that is that you cannot tie an asset to a physical location.  You can add multiple sites, but cannot associate an inventory item to a physical location.  This is where <a href=\"https:\/\/github.com\/netbox-community\/netbox\">Netbox<\/a> comes in for us, since we have all of our physical locations in <a href=\"https:\/\/github.com\/netbox-community\/netbox\">Netbox<\/a>, we can associate an asset tag ID and asset ID from Rev.IO to a physical location or customer.<\/p>\n\n\n\n<p>Here is what I did, with Python, to make this work;<\/p>\n\n\n\n<p>First, we have to ensure that we import all of our customers from Rev.IO into Netbox, now we have two issues with Rev.IO here.  Their documentation indicates that the <code>ALL<\/code> flag will get you all customer status&#8217; &#8211; OPEN, CLOSED, PENDING etc&#8230; this is untrue, you must run each individually to get them all, the <code>ALL<\/code> flag, returns 0.<\/p>\n\n\n\n<p>We created a custom_field in Netbox called <code>revio<\/code> that is the customer_id from Rev.io to allow pivoting on that id.<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background\"><code>#!\/usr\/bin\/python\nimport requests\nimport json\nimport argparse\nimport sys\nimport re\n\n#Get customer list from Rev.IO and ensure they are all in Netbox\n        r_parms = {\"search.page_size\":\"100000\",\"search.status\":\"OPEN\"}\n        response = requests.request(\"GET\", url + \"Customers\", headers=headers, params=r_parms)\n        netbox_r = requests.request(\"GET\", netbox + \"tenancy\/tenants\/?limit=10000\", headers=netbox_h)\n        #Read JSON in response\n        data = response.json()\n        #Read JSON in netbox\n        netbox_d = netbox_r.json()\n        #Iterate over JSON\n        customercount = 0\n        for i in data&#91;'records']:\n                customercount += 1\n                revio_id = i&#91;'customer_id']\n                netbox_hasit = False\n                for n in netbox_d&#91;'results']:\n                        if n&#91;'custom_fields']&#91;'revio'] == revio_id:\n                                netbox_hasit = True\n                                break\n                if not netbox_hasit:\n                        print(\"No Netbox entry for \" + i&#91;'service_address']&#91;'company_name'] + \" - \" + str(revio_id) + \"Adding it\")\n\t\t\tnetbox_name = i&#91;'service_address']&#91;'company_name']\n\t\t\tnetbox_slug = re.sub('&#91;!@#$\\'\\\".,&amp;()]', '', netbox_name)\n\t\t\tnetbox_slug = netbox_slug.replace(\"\/\", \"-\")\n\t\t\tnetbox_p = {'name': netbox_slug, 'slug': netbox_slug.replace(\" \", \"-\"), 'custom_fields': {'revio':revio_id}}\n\t\t\tsc = requests.post(netbox + \"tenancy\/tenants\/\", json=netbox_p, headers=netbox_h)\n\t\t\tprint(sc.text)<\/code><\/pre>\n\n\n\n<p>The above will check Netbox for existing customers (tenants) that have the matching custom_field value and if not, add them.  Again, you have to change the parms value from OPEN to CLOSED etc. to get everyone.<\/p>\n\n\n\n<p>More to follow in a later post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rev.IO has kind of a terrible asset management interface, (and they&#8217;ve killed their WWW subdomain without a redirect,&#8230; but that&#8217;s another rant) but we&#8217;ve chosen it due to its ability to handle MSP billing, so while it&#8217;s not ideal it&#8217;s &hellip; <a href=\"https:\/\/www.scottharvanek.com\/?p=406\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,1],"tags":[51,50,48,49],"class_list":["post-406","post","type-post","status-publish","format-standard","hentry","category-code","category-opensource","tag-code","tag-netbox","tag-python","tag-rev-io"],"_links":{"self":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts\/406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=406"}],"version-history":[{"count":2,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts\/406\/revisions"}],"predecessor-version":[{"id":428,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=\/wp\/v2\/posts\/406\/revisions\/428"}],"wp:attachment":[{"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scottharvanek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}