@@ -1635,29 +1635,18 @@ class Input(Entity):
16351635 def __init__ (self , service , path , kind = None , ** kwargs ):
16361636 Entity .__init__ (self , service , path , ** kwargs )
16371637 if kind is None :
1638- for kind , kind_path in INPUT_KINDMAP .iteritems ():
1639- if kind_path in path :
1640- self .kind = kind
1641- break
1638+ path_segments = path .split ('/' )
1639+ i = path_segments .index ('inputs' )
1640+ self .kind = '/' .join (path_segments [i + 1 :- 1 ])
16421641 assert self .kind is not None
16431642 else :
16441643 self .kind = kind
16451644
1646- # Directory of known input kinds that maps from input kind to path relative
1647- # to data/inputs, eg: inputs of kind 'splunktcp' map to a relative path
1648- # of 'tcp/cooked' and therefore an endpoint path of 'data/inputs/tcp/cooked'.
1649- INPUT_KINDMAP = {
1650- 'ad' : "ad" ,
1651- 'monitor' : "monitor" ,
1652- 'registry' : "registry" ,
1653- 'script' : "script" ,
1654- 'tcp' : "tcp/raw" ,
1655- 'splunktcp' : "tcp/cooked" ,
1656- 'udp' : "udp" ,
1657- 'win-event-log-collections' : "win-event-log-collections" ,
1658- 'win-perfmon' : "win-perfmon" ,
1659- 'win-wmi-collections' : "win-wmi-collections"
1660- }
1645+ # Maintain compatibility with older kind labels
1646+ if self .kind == 'tcp/raw' :
1647+ self .kind = 'tcp'
1648+ if self .kind == 'tcp/cooked' :
1649+ self .kind = 'splunktcp'
16611650
16621651# Inputs is a "kinded" collection, which is a heterogenous collection where
16631652# each item is tagged with a kind, that provides a single merged view of all
@@ -1670,14 +1659,13 @@ class Inputs(Collection):
16701659
16711660 def __init__ (self , service , kindmap = None ):
16721661 Collection .__init__ (self , service , PATH_INPUTS , item = Input )
1673- self ._kindmap = kindmap if kindmap is not None else INPUT_KINDMAP
1674-
1662+
16751663 def __getitem__ (self , key ):
16761664 if isinstance (key , tuple ) and len (key ) == 2 :
16771665 # Fetch a single kind
16781666 kind , key = key
16791667 try :
1680- kind_path = self ._kindmap [ kind ]
1668+ kind_path = self .kindpath ( kind )
16811669 response = self .get (kind_path + "/" + key )
16821670 entries = self ._load_list (response )
16831671 if len (entries ) > 1 :
@@ -1695,9 +1683,9 @@ def __getitem__(self, key):
16951683 # Iterate over all the kinds looking for matches.
16961684 kind = None
16971685 candidate = None
1698- for kind , kind_path in self ._kindmap . iteritems () :
1686+ for kind in self .kinds :
16991687 try :
1700- response = self .get (kind_path + "/" + key )
1688+ response = self .get (kind + "/" + key )
17011689 entries = self ._load_list (response )
17021690 if len (entries ) > 1 :
17031691 raise AmbiguousReferenceException ("Found multiple inputs of kind %s named %s." % (kind , key ))
@@ -1729,9 +1717,9 @@ def __contains__(self, key):
17291717 # Without a kind, we want to minimize the number of round trips to the server, so we
17301718 # reimplement some of the behavior of __getitem__ in order to be able to stop searching
17311719 # on the first hit.
1732- for kind , kind_path in self ._kindmap . iteritems () :
1720+ for kind in self .kinds :
17331721 try :
1734- response = self .get (kind_path + "/" + key )
1722+ response = self .get (self . kindpath ( kind ) + "/" + key )
17351723 entries = self ._load_list (response )
17361724 if len (entries ) > 0 :
17371725 return True
@@ -1758,8 +1746,9 @@ def create(self, kind, name, **kwargs):
17581746 :return: The new input.
17591747 """
17601748 kindpath = self .kindpath (kind )
1761- self .service .post (kindpath , name = name , ** kwargs )
1762- return Input (self .service , _path (kindpath , name ), kind )
1749+ self .post (kindpath , name = name , ** kwargs )
1750+ path = _path (self .path + kindpath , name )
1751+ return Input (self .service , path , kind )
17631752
17641753 def delete (self , kind , name = None ):
17651754 """Removes an input from the collection.
@@ -1779,18 +1768,40 @@ def itemmeta(self, kind):
17791768 content = _load_atom (response , MATCH_ENTRY_CONTENT )
17801769 return _parse_atom_metadata (content )
17811770
1771+ def _get_kind_list (self , subpath = []):
1772+ kinds = []
1773+ response = self .get ('/' .join (subpath ))
1774+ content = _load_atom_entries (response )
1775+ for entry in content :
1776+ this_subpath = subpath + [entry .title ]
1777+ if entry .title == 'all' or this_subpath == ['tcp' ,'ssl' ]:
1778+ continue
1779+ elif 'create' in [x .rel for x in entry .link ]:
1780+ kinds .append ('/' .join (subpath + [entry .title ]))
1781+ else :
1782+ subkinds = self ._get_kind_list (subpath + [entry .title ])
1783+ kinds .extend (subkinds )
1784+ return kinds
1785+
17821786 @property
1783- def kinds (self ):
1784- """Returns the list of input kinds that this collection may
1785- contain."""
1786- return self ._kindmap .keys ()
1787+ def kinds (self , subpath = []):
1788+ """Returns the list of input kinds that this collection contains."""
1789+ return self ._get_kind_list ()
17871790
17881791 def kindpath (self , kind ):
17891792 """Returns a path to the resources for a given input kind.
17901793
17911794 :param `kind`: The input kind.
17921795 """
1793- return self .path + self ._kindmap [kind ]
1796+ if kind in self .kinds :
1797+ return kind
1798+ # Special cases
1799+ elif kind == 'tcp' :
1800+ return 'tcp/raw'
1801+ elif kind == 'splunktcp' :
1802+ return 'tcp/cooked'
1803+ else :
1804+ raise ValueError ("No such kind on server: %s" % kind )
17941805
17951806 def list (self , * kinds , ** kwargs ):
17961807 """Returns a list of inputs that belong to the collection. You can also
@@ -1816,7 +1827,7 @@ def list(self, *kinds, **kwargs):
18161827 :param `kinds`: The input kinds to return (optional).
18171828 """
18181829 if len (kinds ) == 0 :
1819- kinds = self ._kindmap . keys ()
1830+ kinds = self .kinds
18201831 if len (kinds ) == 1 :
18211832 kind = kinds [0 ]
18221833 logging .debug ("Inputs.list taking short circuit branch for single kind." )
@@ -1847,7 +1858,7 @@ def list(self, *kinds, **kwargs):
18471858 for kind in kinds :
18481859 response = None
18491860 try :
1850- response = self .service . get (self .kindpath (kind ),
1861+ response = self .get (self .kindpath (kind ),
18511862 search = search )
18521863 except HTTPError as e :
18531864 if e .status == 404 :
0 commit comments