Change Mail Address
[racktables-contribs] / QuickSearch.vbs
1 '======================================================================
2 'Racktables QuickSearch VBScript (Windows only)
3 'By goran.tornqvist@cypoint.se
4 'License: Freeware - Do what you please with it :)
5 'Description: Performs a quick search for an object or a hostname in racktables and displays its ip address.
6 'INSTALL:
7 '- Download and install MySQL Connector/ODBC: http://dev.mysql.com/downloads/connector/odbc/
8 '- Put the script on your harddrive and rename it from .txt to .vbs
9 '- Create a shortcut on your desktop to "wscript.exe c:\path\to\script.vbs"
10 '- Right click the shortcut and pin it to the taskbar for a quick way to start the script
11 '- Change the strDSN variable below (server/database/user/password).
12 ' The mysql user should preferably be a read only user and only allow SELECT on specific columns, see strSQL below to tighten permissions.
13 ' SECURITY NOTE: Be aware - Script bypasses racktables authentication so make sure you don´t break your company´s security policy ;)
14 '======================================================================
15
16 Const strDSN = "Driver={MySQL ODBC 5.1 Driver};Server=server;Database=database; User=user;Password=password;Option=3;"
17
18 SearchString = InputBox("Enter object name or host name","Racktables QuickSearch","")
19
20 If SearchString <> "" Then
21
22 strSQL = "select " & _
23 " RackObject.name as ipaddr_name, " & _
24 " CONVERT(INET_NTOA(IPv4Allocation.ip), CHAR) as ipaddr, " & _
25 " CONCAT(IFNULL(IPv4Allocation.name, 'unknown'), '/', IPv4Allocation.type) as comment " & _
26 "from IPv4Allocation " & _
27 " left join RackObject on IPv4Allocation.object_id = RackObject.id " & _
28 "where RackObject.name like '%" & SearchString & "%'" & _
29 "union " & _
30 "select " & _
31 " IPv4Address.name as ipaddr_name, " & _
32 " CONVERT(INET_NTOA(IPv4Address.ip), CHAR) as ipaddr, " & _
33 " CONCAT('reserved: ', IPv4Address.reserved) as comment " & _
34 "from IPv4Address " & _
35 "where IPv4Address.name like '%" & SearchString & "%'"
36
37
38 Set objConn = CreateObject("ADODB.Connection")
39 objConn.Open strDSN
40
41 Set objRs = objConn.Execute(strSQL)
42
43 If (objRs.BOF AND objRs.EOF) Then
44 Matches = "No matches on search string " & SearchString & "."
45 Else
46
47 Do While NOT objRs.EOF
48 If objRs.Fields("comment").Value <> "" Then
49 Comment = " (" & objRs.Fields("comment").Value & ")"
50 Else
51 Comment = ""
52 End If
53 Chars = 35 - Len(objRs.Fields("ipaddr_name").Value)
54 StrTab = ""
55 For i = 0 To Chars
56 StrTab = StrTab & " "
57 Next
58 Matches = Matches & objRs.Fields("ipaddr_name").Value & StrTab & objRs.Fields("ipaddr").Value & Comment & vbCrLf
59
60
61 objRs.MoveNext
62 Loop
63
64 End If
65
66 objRs.Close
67 Set objRs = Nothing
68
69 objConn.Close
70 Set objConn = Nothing
71
72 MsgBox Matches,,"Racktables QuickSearch"
73
74 Else
75
76 MsgBox "Search aborted!",,"Racktables QuickSearch"
77
78 End If